Skip to content

Commit c512c51

Browse files
Move offsets downcasting to MultiIndex._engine
1 parent 3ab8601 commit c512c51

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

pandas/_libs/index.pyx

+1-2
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,7 @@ cdef class BaseMultiIndexCodesEngine:
712712
Pre-calculated offsets, one for each level of the index.
713713
"""
714714
self.levels = levels
715-
# Downcast the type if possible, to prevent upcasting when shifting codes:
716-
self.offsets = offsets.astype(np.min_scalar_type(offsets[0]), copy=False)
715+
self.offsets = offsets
717716

718717
# Transform labels in a single array, and add 2 so that we are working
719718
# with positive integers (-1 for NaN becomes 1). This enables us to

pandas/core/indexes/multi.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,9 @@ def _engine(self):
12011201
# equivalent to sorting lexicographically the codes themselves. Notice
12021202
# that each level needs to be shifted by the number of bits needed to
12031203
# represent the _previous_ ones:
1204-
offsets = np.concatenate([lev_bits[1:], [0]]).astype("uint64")
1204+
offsets = np.concatenate([lev_bits[1:], [0]])
1205+
# Downcast the type if possible, to prevent upcasting when shifting codes:
1206+
offsets = offsets.astype(np.min_scalar_type(int(offsets[0])))
12051207

12061208
# Check the total number of bits needed for our representation:
12071209
if lev_bits[0] > 64:

0 commit comments

Comments
 (0)