Skip to content

Commit f572ec4

Browse files
ArtificialQualiajreback
authored andcommitted
PERF: Fix performance regression with Series statistical ops (#25952) (#25953)
1 parent 48ea04f commit f572ec4

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

pandas/core/groupby/grouper.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -522,21 +522,17 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
522522
any_arraylike = any(isinstance(g, (list, tuple, Series, Index, np.ndarray))
523523
for g in keys)
524524

525-
try:
525+
# is this an index replacement?
526+
if (not any_callable and not any_arraylike and not any_groupers and
527+
match_axis_length and level is None):
526528
if isinstance(obj, DataFrame):
527-
all_in_columns_index = all(g in obj.columns or g in obj.index.names
528-
for g in keys)
529+
all_in_columns_index = all(g in obj.columns or g in
530+
obj.index.names for g in keys)
529531
elif isinstance(obj, Series):
530532
all_in_columns_index = all(g in obj.index.names for g in keys)
531-
else:
532-
all_in_columns_index = False
533-
except Exception:
534-
all_in_columns_index = False
535533

536-
if (not any_callable and not all_in_columns_index and
537-
not any_arraylike and not any_groupers and
538-
match_axis_length and level is None):
539-
keys = [com.asarray_tuplesafe(keys)]
534+
if not all_in_columns_index:
535+
keys = [com.asarray_tuplesafe(keys)]
540536

541537
if isinstance(level, (tuple, list)):
542538
if key is None:

0 commit comments

Comments
 (0)