Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: hdf can't deal with ea dtype columns #56194

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading