Skip to content

Commit 2d812e2

Browse files
Backport PR #56194 on branch 2.1.x (BUG: hdf can't deal with ea dtype columns) (#56199)
Backport PR #56194: BUG: hdf can't deal with ea dtype columns Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 9181930 commit 2d812e2

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 :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55753`)
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
@@ -56,7 +56,6 @@
5656
is_bool_dtype,
5757
is_complex_dtype,
5858
is_list_like,
59-
is_object_dtype,
6059
is_string_dtype,
6160
needs_i8_conversion,
6261
)
@@ -2645,7 +2644,7 @@ class DataIndexableCol(DataCol):
26452644
is_data_indexable = True
26462645

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

pandas/tests/io/pytables/test_round_trip.py

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

0 commit comments

Comments
 (0)