Skip to content

Commit 995d1c8

Browse files
committed
Better implementation
1 parent b961ff5 commit 995d1c8

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

pandas/core/groupby/ops.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ def _ob_index_and_ids(
867867
names=names,
868868
verify_integrity=False,
869869
)
870-
if not consistent_sorting:
870+
if not consistent_sorting and len(ob_index) > 0:
871871
# Sort by the levels where the corresponding sort argument is True
872872
n_levels = len(sorts)
873873
drop_levels = [
@@ -881,9 +881,7 @@ def _ob_index_and_ids(
881881
sorter = ob_index.argsort()
882882
ob_index = ob_index.take(sorter)
883883
_, index = np.unique(sorter, return_index=True)
884-
na_ids = ob_ids == -1
885-
if not na_ids.all():
886-
ob_ids = np.where(na_ids, -1, index.take(ob_ids))
884+
ob_ids = np.where(ob_ids == -1, -1, index.take(ob_ids))
887885
ob_ids = ensure_platform_int(ob_ids)
888886
return ob_index, ob_ids
889887

0 commit comments

Comments
 (0)