From dbd8b4c2b108cd938a189e69deefb138841c16fd Mon Sep 17 00:00:00 2001 From: Mali Akmanalp Date: Mon, 22 May 2017 17:06:01 -0700 Subject: [PATCH] BUG: Handle np strings in index.name in HDF #13492 --- pandas/io/pytables.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index b838260d1f73c..e47265176aeff 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -73,6 +73,14 @@ def _ensure_encoding(encoding): return encoding +def _ensure_python_type(obj): + """ Ensure that non-python types get converted to python native type + equivalents.""" + if isinstance(obj, np.generic): + return obj.item() + return obj + + Term = Expr @@ -2567,7 +2575,7 @@ def read_index_node(self, node, start=None, stop=None): name = None if 'name' in node._v_attrs: - name = node._v_attrs.name + name = _ensure_decoded(_ensure_python_type(node._v_attrs.name)) index_class = self._alias_to_class(getattr(node._v_attrs, 'index_class', ''))