Skip to content

Commit b147e87

Browse files
PERF: Fix performance regression with Series statistical ops (pandas-dev#25952)
1 parent 00c119c commit b147e87

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

doc/source/whatsnew/v0.25.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ Performance Improvements
246246
- Improved performance of :meth:`pandas.core.groupby.GroupBy.quantile` (:issue:`20405`)
247247
- Improved performance of :meth:`read_csv` by faster tokenizing and faster parsing of small float numbers (:issue:`25784`)
248248
- Improved performance of :meth:`read_csv` by faster parsing of N/A and boolean values (:issue:`25804`)
249+
- Fixed performance regression in :class:`Series` statistical operations (:issue:`25952`)
249250

250251
.. _whatsnew_0250.bug_fixes:
251252

pandas/core/groupby/grouper.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -520,21 +520,21 @@ def _get_grouper(obj, key=None, axis=0, level=None, sort=True,
520520
any_arraylike = any(isinstance(g, (list, tuple, Series, Index, np.ndarray))
521521
for g in keys)
522522

523-
try:
524-
if isinstance(obj, DataFrame):
525-
all_in_columns_index = all(g in obj.columns or g in obj.index.names
526-
for g in keys)
527-
elif isinstance(obj, Series):
528-
all_in_columns_index = all(g in obj.index.names for g in keys)
529-
else:
523+
if (not any_callable and not any_arraylike and not any_groupers and
524+
match_axis_length and level is None):
525+
try:
526+
if isinstance(obj, DataFrame):
527+
all_in_columns_index = all(g in obj.columns or g in
528+
obj.index.names for g in keys)
529+
elif isinstance(obj, Series):
530+
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:
530534
all_in_columns_index = False
531-
except Exception:
532-
all_in_columns_index = False
533535

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

539539
if isinstance(level, (tuple, list)):
540540
if key is None:

0 commit comments

Comments
 (0)