Skip to content

Commit

Permalink
BUG: hdf can't deal with ea dtype columns (#56194)
Browse files Browse the repository at this point in the history
  • Loading branch information
phofl authored Nov 27, 2023
1 parent 4b6a80e commit 3fc8320
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 :class:`Series` constructor raising DeprecationWarning when ``index`` is a list of :class:`Series` (:issue:`55228`)
- 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 @@ -57,7 +57,6 @@
is_bool_dtype,
is_complex_dtype,
is_list_like,
is_object_dtype,
is_string_dtype,
needs_i8_conversion,
)
Expand Down Expand Up @@ -2647,7 +2646,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 @@ -531,3 +531,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 3fc8320

Please sign in to comment.