Skip to content

Commit a0d538a

Browse files
committed
fixups
1 parent e987daf commit a0d538a

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

pandas/_libs/arrays.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ cdef class BitmaskArray:
469469
def __getitem__(self, key):
470470
cdef Py_ssize_t ckey
471471
# to_numpy can be expensive, so try to avoid for simple cases
472-
if isinstance(key, int):
472+
if isinstance(key, int) and self.ndim == 1:
473473
ckey = key
474474
if ckey >= 0 and ckey < self.bitmap.size_bits:
475475
return bool(ArrowBitGet(self.bitmap.buffer.data, ckey))

pandas/core/arrays/masked.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,13 @@ def __getitem__(self, item: SequenceIndexer) -> Self:
191191
def __getitem__(self, item: PositionalIndexer) -> Self | Any:
192192
item = check_array_indexer(self, item)
193193

194-
# TODO: some of the numpy semantics for handling 2D indexing
195-
# are not implemented in the bitmaskarray, hence the to_numpy()
196-
# requirement, though that slows things down
197-
np_mask = self._mask.to_numpy()
198-
newmask = np_mask[item]
194+
newmask = self._mask[item]
199195
if is_bool(newmask):
200196
# This is a scalar indexing
201197
if newmask:
202198
return self.dtype.na_value
203199
return self._data[item]
204200

205-
# sending self._mask avoids copy of buffer
206-
if np.array_equal(newmask, np_mask):
207-
return self._simple_new(self._data[item], self._mask)
208-
209201
return self._simple_new(self._data[item], newmask)
210202

211203
def pad_or_backfill(

pandas/tests/arrays/masked/test_bitmask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
pytest.param(np.array([True, False] * 8), bytes([0x55, 0x55]), id="multibyte"),
2020
pytest.param(
2121
np.array([[False, False], [True, True], [False, False]])[:, 0],
22-
[False, True, False],
22+
bytes([0x2]),
2323
id="non-contiguous",
2424
),
2525
],

0 commit comments

Comments
 (0)