Skip to content

Commit e839cb4

Browse files
committed
fix: assert proper nan_index initialization
1 parent 6f98429 commit e839cb4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pandas/core/reshape/reshape.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,10 @@ def _repeater(self) -> np.ndarray:
419419
# Otherwise, we just use each level item exactly once:
420420
stride = len(self.removed_level) + self.has_nan
421421
repeater = np.arange(stride) - self.lift
422-
if self.has_nan and self.lift == 0:
422+
if self.has_nan and not self.sort:
423+
assert self.unique_nan_index > -1, (
424+
"`unique_nan_index` not properly initialized"
425+
)
423426
# assign -1 where should be nan according to the unique values.
424427
repeater[self.unique_nan_index] = -1
425428
# compensate for the removed index level

0 commit comments

Comments
 (0)