Skip to content

Commit

Permalink
Backport PR pandas-dev#56194 on branch 2.1.x (BUG: hdf can't deal wit…
Browse files Browse the repository at this point in the history
…h ea dtype columns) (pandas-dev#56199)

Backport PR pandas-dev#56194: BUG: hdf can't deal with ea dtype columns

Co-authored-by: Patrick Hoefler <[email protected]>
  • Loading branch information
meeseeksmachine and phofl authored Nov 27, 2023
1 parent 9181930 commit 2d812e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.1.4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Bug fixes
- Bug in :meth:`DataFrame.apply` where passing ``raw=True`` ignored ``args`` passed to the applied function (:issue:`55753`)
- Bug in :meth:`Index.__getitem__` returning wrong result for Arrow dtypes and negative stepsize (:issue:`55832`)
- Fixed bug in :meth:`DataFrame.__setitem__` casting :class:`Index` with object-dtype to PyArrow backed strings when ``infer_string`` option is set (:issue:`55638`)
- Fixed bug in :meth:`DataFrame.to_hdf` raising when columns have ``StringDtype`` (:issue:`55088`)
- Fixed bug in :meth:`Index.insert` casting object-dtype to PyArrow backed strings when ``infer_string`` option is set (:issue:`55638`)
- Fixed bug in :meth:`Series.str.translate` losing object dtype when string option is set (:issue:`56152`)

Expand Down
3 changes: 1 addition & 2 deletions pandas/io/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
is_bool_dtype,
is_complex_dtype,
is_list_like,
is_object_dtype,
is_string_dtype,
needs_i8_conversion,
)
Expand Down Expand Up @@ -2645,7 +2644,7 @@ class DataIndexableCol(DataCol):
is_data_indexable = True

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

Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/io/pytables/test_round_trip.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,3 +526,18 @@ def test_round_trip_equals(tmp_path, setup_path):
tm.assert_frame_equal(df, other)
assert df.equals(other)
assert other.equals(df)


def test_infer_string_columns(tmp_path, setup_path):
# GH#
pytest.importorskip("pyarrow")
path = tmp_path / setup_path
with pd.option_context("future.infer_string", True):
df = DataFrame(1, columns=list("ABCD"), index=list(range(10))).set_index(
["A", "B"]
)
expected = df.copy()
df.to_hdf(path, key="df", format="table")

result = read_hdf(path, "df")
tm.assert_frame_equal(result, expected)

0 comments on commit 2d812e2

Please sign in to comment.