Skip to content

Commit 148c47e

Browse files
Chang Shewesm
Chang She
authored andcommitted
Stop storing class reference in HDFStore #1235
1 parent 2393ba9 commit 148c47e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

pandas/io/pytables.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ def _write_index(self, group, key, index):
580580
node._v_attrs.name = index.name
581581

582582
if isinstance(index, (DatetimeIndex, PeriodIndex, IntIndex)):
583-
node._v_attrs.index_class = type(index)
583+
node._v_attrs.index_class = _class_to_alias(type(index))
584584

585585
if hasattr(index, 'freq'):
586586
node._v_attrs.freq = index.freq
@@ -670,9 +670,7 @@ def _read_index_node(self, node):
670670
if 'name' in node._v_attrs:
671671
name = node._v_attrs.name
672672

673-
index_class = getattr(node._v_attrs, 'index_class', Index)
674-
675-
factory = _get_index_factory(index_class)
673+
index_class = _alias_to_class(getattr(node._v_attrs, 'index_class', ''))
676674

677675
kwargs = {}
678676
if 'freq' in node._v_attrs:
@@ -1012,6 +1010,22 @@ def _is_table_type(group):
10121010
# new node, e.g.
10131011
return False
10141012

1013+
_index_type_map = {DatetimeIndex : 'datetime',
1014+
PeriodIndex : 'period',
1015+
IntIndex : 'sparse integer'}
1016+
1017+
_reverse_index_map = {}
1018+
for k, v in _index_type_map.iteritems():
1019+
_reverse_index_map[v] = k
1020+
1021+
def _class_to_alias(cls):
1022+
return _index_type_map.get(cls, '')
1023+
1024+
def _alias_to_class(alias):
1025+
if isinstance(alias, type):
1026+
return alias
1027+
return _reverse_index_map.get(alias, Index)
1028+
10151029
class Selection(object):
10161030
"""
10171031
Carries out a selection operation on a tables.Table object.

0 commit comments

Comments
 (0)