Skip to content

Commit 3e68b42

Browse files
authored
BUG: convert_dtypes raising when preserving object dtype (#56585)
1 parent 6a65c64 commit 3e68b42

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/core/internals/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def astype(
746746
Block
747747
"""
748748
values = self.values
749-
if squeeze and values.ndim == 2:
749+
if squeeze and values.ndim == 2 and is_1d_only_ea_dtype(dtype):
750750
if values.shape[0] != 1:
751751
raise ValueError("Can not squeeze with more than one column.")
752752
values = values[0, :] # type: ignore[call-overload]

pandas/tests/frame/methods/test_convert_dtypes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,10 @@ def test_convert_dtypes_avoid_block_splitting(self):
193193
)
194194
tm.assert_frame_equal(result, expected)
195195
assert result._mgr.nblocks == 2
196+
197+
def test_convert_dtypes_from_arrow(self):
198+
# GH#56581
199+
df = pd.DataFrame([["a", datetime.time(18, 12)]], columns=["a", "b"])
200+
result = df.convert_dtypes()
201+
expected = df.astype({"a": "string[python]"})
202+
tm.assert_frame_equal(result, expected)

0 commit comments

Comments
 (0)