Skip to content

BUG: fix construction of NonConsolidatableBlock with inconsistent ndim (#27786) #27806

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

Merged
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
2 changes: 2 additions & 0 deletions pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ def make_block_same_class(self, values, placement=None, ndim=None, dtype=None):
)
if placement is None:
placement = self.mgr_locs
if ndim is None:
ndim = self.ndim
return make_block(
values, placement=placement, ndim=ndim, klass=self.__class__, dtype=dtype
)
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/extension/base/getitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,9 @@ def test_reindex_non_na_fill_value(self, data_missing):
expected = pd.Series(data_missing._from_sequence([na, valid, valid]))

self.assert_series_equal(result, expected)

def test_loc_len1(self, data):
# see GH-27785 take_nd with indexer of len 1 resulting in wrong ndim
df = pd.DataFrame({"A": data})
res = df.loc[[0], "A"]
assert res._data._block.ndim == 1