Skip to content

Commit 202de07

Browse files
committed
fixups
1 parent 8149e03 commit 202de07

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pandas/_libs/arrays.pyx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ cdef class BitmaskArray:
472472
cdef Py_ssize_t start, stop, step
473473
cdef BitmaskArray bma
474474
cdef ArrowBitmap bitmap
475-
cdef int64_t nbytes
475+
cdef int64_t nbytes, nbits
476476
cdef BitmaskArray self_ = self
477477
# to_numpy can be expensive, so try to avoid for simple cases
478478
if isinstance(key, int) and self.ndim == 1:
@@ -488,21 +488,23 @@ cdef class BitmaskArray:
488488
PySlice_Unpack(key, &start, &stop, &step)
489489
if start == 0 and stop > 0 and step == 1:
490490
if stop > self_.bitmap.size_bits:
491-
stop = self_.bitmap.size_bits
491+
nbits = self_.bitmap.size_bits
492+
else:
493+
nbits = stop
492494

493495
nbytes = (stop + 7) // 8
494496

495497
bma = BitmaskArray.__new__(BitmaskArray)
496498
ArrowBitmapInit(&bitmap)
497-
ArrowBitmapReserve(&bitmap, nbytes)
499+
ArrowBitmapReserve(&bitmap, nbits)
498500
memcpy(bitmap.buffer.data, self_.bitmap.buffer.data, nbytes)
499501
bitmap.buffer.size_bytes = nbytes
500502
bitmap.size_bits = stop
501503

502504
bma.bitmap = bitmap
503505
bma.buffer_owner = True
504506
bma.ndim = self_.ndim
505-
bma.shape[0] = stop
507+
bma.shape[0] = nbits
506508
bma.strides = self_.strides
507509
bma.parent = False
508510

pandas/tests/arrays/masked/test_bitmask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def test_memoryview(array, expected):
463463

464464

465465
def test_bitmask_array_shape_from_sliced_bitmask():
466-
orig_bma = BitmaskArray([True] * 100)
466+
orig_bma = BitmaskArray(np.array([True] * 100))
467467
bma = BitmaskArray(orig_bma[:10])
468468

469469
assert bma.shape == (10,)

0 commit comments

Comments
 (0)