Skip to content

Commit 850ceb7

Browse files
Backport PR #55363 on branch 2.1.x (BUG: ndim of string block incorrect with string inference) (#55376)
Backport PR #55363: BUG: ndim of string block incorrect with string inference Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 7e8398c commit 850ceb7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/core/internals/construction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ def ndarray_to_mgr(
383383
new_block(
384384
dtype.construct_array_type()._from_sequence(data, dtype=dtype),
385385
BlockPlacement(slice(i, i + 1)),
386-
ndim=1,
386+
ndim=2,
387387
)
388388
for i, data in enumerate(obj_columns)
389389
]

pandas/tests/frame/test_constructors.py

+7
Original file line numberDiff line numberDiff line change
@@ -2743,6 +2743,13 @@ def test_frame_string_inference_array_string_dtype(self):
27432743
df = DataFrame(np.array([["a", "c"], ["b", "d"]]), columns=["a", "b"])
27442744
tm.assert_frame_equal(df, expected)
27452745

2746+
def test_frame_string_inference_block_dim(self):
2747+
# GH#55363
2748+
pytest.importorskip("pyarrow")
2749+
with pd.option_context("future.infer_string", True):
2750+
df = DataFrame(np.array([["hello", "goodbye"], ["hello", "Hello"]]))
2751+
assert df._mgr.blocks[0].ndim == 2
2752+
27462753

27472754
class TestDataFrameConstructorIndexInference:
27482755
def test_frame_from_dict_of_series_overlapping_monthly_period_indexes(self):

0 commit comments

Comments
 (0)