Skip to content

Commit 3fc8320

Browse files
authored
BUG: hdf can't deal with ea dtype columns (#56194)
1 parent 4b6a80e commit 3fc8320

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/source/whatsnew/v2.1.4.rst

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Bug fixes
2424
- Bug in :class:`Series` constructor raising DeprecationWarning when ``index`` is a list of :class:`Series` (:issue:`55228`)
2525
- Bug in :meth:`Index.__getitem__` returning wrong result for Arrow dtypes and negative stepsize (:issue:`55832`)
2626
- Fixed bug in :meth:`DataFrame.__setitem__` casting :class:`Index` with object-dtype to PyArrow backed strings when ``infer_string`` option is set (:issue:`55638`)
27+
- Fixed bug in :meth:`DataFrame.to_hdf` raising when columns have ``StringDtype`` (:issue:`55088`)
2728
- Fixed bug in :meth:`Index.insert` casting object-dtype to PyArrow backed strings when ``infer_string`` option is set (:issue:`55638`)
2829
- Fixed bug in :meth:`Series.str.translate` losing object dtype when string option is set (:issue:`56152`)
2930

pandas/io/pytables.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
is_bool_dtype,
5858
is_complex_dtype,
5959
is_list_like,
60-
is_object_dtype,
6160
is_string_dtype,
6261
needs_i8_conversion,
6362
)
@@ -2647,7 +2646,7 @@ class DataIndexableCol(DataCol):
26472646
is_data_indexable = True
26482647

26492648
def validate_names(self) -> None:
2650-
if not is_object_dtype(Index(self.values).dtype):
2649+
if not is_string_dtype(Index(self.values).dtype):
26512650
# TODO: should the message here be more specifically non-str?
26522651
raise ValueError("cannot have non-object label DataIndexableCol")
26532652

pandas/tests/io/pytables/test_round_trip.py

+15
Original file line numberDiff line numberDiff line change
@@ -531,3 +531,18 @@ def test_round_trip_equals(tmp_path, setup_path):
531531
tm.assert_frame_equal(df, other)
532532
assert df.equals(other)
533533
assert other.equals(df)
534+
535+
536+
def test_infer_string_columns(tmp_path, setup_path):
537+
# GH#
538+
pytest.importorskip("pyarrow")
539+
path = tmp_path / setup_path
540+
with pd.option_context("future.infer_string", True):
541+
df = DataFrame(1, columns=list("ABCD"), index=list(range(10))).set_index(
542+
["A", "B"]
543+
)
544+
expected = df.copy()
545+
df.to_hdf(path, key="df", format="table")
546+
547+
result = read_hdf(path, "df")
548+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)