Skip to content

Commit

Permalink
Backport PR #55363 on branch 2.1.x (BUG: ndim of string block incorre…
Browse files Browse the repository at this point in the history
…ct with string inference) (#55376)

Backport PR #55363: BUG: ndim of string block incorrect with string inference

Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and phofl committed Oct 3, 2023
1 parent 7e8398c commit 850ceb7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def ndarray_to_mgr(
new_block(
dtype.construct_array_type()._from_sequence(data, dtype=dtype),
BlockPlacement(slice(i, i + 1)),
ndim=1,
ndim=2,
)
for i, data in enumerate(obj_columns)
]
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/frame/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2743,6 +2743,13 @@ def test_frame_string_inference_array_string_dtype(self):
df = DataFrame(np.array([["a", "c"], ["b", "d"]]), columns=["a", "b"])
tm.assert_frame_equal(df, expected)

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


class TestDataFrameConstructorIndexInference:
def test_frame_from_dict_of_series_overlapping_monthly_period_indexes(self):
Expand Down

0 comments on commit 850ceb7

Please sign in to comment.