Skip to content

Commit d349828

Browse files
committed
MAINT: add support for Pandas 3.0rc
1 parent 715cbca commit d349828

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

larray/core/array.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6981,8 +6981,23 @@ def to_hdf(self, filepath, key) -> None:
69816981
>>> a.to_hdf('test.h5', 'arrays/a') # doctest: +SKIP
69826982
"""
69836983
key = _translate_group_key_hdf(key)
6984+
def ensure_non_string_index(index):
6985+
if (isinstance(index, pd.MultiIndex) and
6986+
any(isinstance(dt, pd.StringDtype) for dt in index.dtypes)):
6987+
obj_levels = [pd.Index(level_labels, dtype=object)
6988+
for level_labels in index.levels]
6989+
index = pd.MultiIndex(obj_levels, index.codes, names=index.names)
6990+
return index
6991+
69846992
with LHDFStore(filepath) as store:
6985-
store.put(key, self.to_frame())
6993+
df = self.to_frame()
6994+
# workaround for https://github.com/pandas-dev/pandas/issues/63412
6995+
# Since we created the dataframe ourselves, we can just
6996+
# replace the index inplace
6997+
df.index = ensure_non_string_index(df.index)
6998+
df.columns = ensure_non_string_index(df.columns)
6999+
7000+
store.put(key, df)
69867001
attrs = store.get_storer(key).attrs
69877002
attrs.type = 'Array'
69887003
attrs.writer = 'LArray'

larray/core/group.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,9 @@ def _to_key(v, stack_depth=1, parse_single_int=False) -> Key:
591591
return cls(key, name=name, axis=axis)
592592
else:
593593
return _seq_str_to_seq(v, stack_depth + 1, parse_single_int=parse_single_int)
594-
elif v is Ellipsis or np.isscalar(v) or isinstance(v, (Group, slice, list, np.ndarray, ABCArray, OrderedSet)):
594+
elif (v is Ellipsis or np.isscalar(v) or
595+
isinstance(v, (Group, slice, list, np.ndarray, ABCArray, OrderedSet,
596+
pd.arrays.ArrowStringArray))):
595597
return v
596598
else:
597599
raise TypeError(f"{v} has an invalid type ({type(v).__name__}) for a key")

0 commit comments

Comments
 (0)