Skip to content

Commit 180098a

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

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pandas/_libs/index.pyx

+3-5
Original file line numberDiff line numberDiff line change
@@ -699,21 +699,19 @@ cdef class BaseMultiIndexCodesEngine:
699699
Keys are located by first locating each component against the respective
700700
level, then locating (the integer representation of) codes.
701701
"""
702-
def __init__(self, object levels, object labels,
703-
ndarray[uint64_t, ndim=1] offsets):
702+
def __init__(self, object levels, object labels, ndarray offsets):
704703
"""
705704
Parameters
706705
----------
707706
levels : list-like of numpy arrays
708707
Levels of the MultiIndex.
709708
labels : list-like of numpy arrays of integer dtype
710709
Labels of the MultiIndex.
711-
offsets : numpy array of uint64 dtype
710+
offsets : numpy array of int dtype
712711
Pre-calculated offsets, one for each level of the index.
713712
"""
714713
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)
714+
self.offsets = offsets
717715

718716
# Transform labels in a single array, and add 2 so that we are working
719717
# 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)