Skip to content

Commit 209c29e

Browse files
authored
CLN: Avoid importing Series in core.aggregation (#36612)
1 parent 31788da commit 209c29e

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

pandas/core/aggregation.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from collections import defaultdict
77
from functools import partial
88
from typing import (
9+
TYPE_CHECKING,
910
Any,
1011
Callable,
1112
DefaultDict,
@@ -26,7 +27,9 @@
2627
from pandas.core.base import SpecificationError
2728
import pandas.core.common as com
2829
from pandas.core.indexes.api import Index
29-
from pandas.core.series import Series
30+
31+
if TYPE_CHECKING:
32+
from pandas.core.series import Series
3033

3134

3235
def reconstruct_func(
@@ -281,7 +284,7 @@ def relabel_result(
281284
func: Dict[str, List[Union[Callable, str]]],
282285
columns: Iterable[Label],
283286
order: Iterable[int],
284-
) -> Dict[Label, Series]:
287+
) -> Dict[Label, "Series"]:
285288
"""
286289
Internal function to reorder result if relabelling is True for
287290
dataframe.agg, and return the reordered result in dict.
@@ -308,10 +311,10 @@ def relabel_result(
308311
reordered_indexes = [
309312
pair[0] for pair in sorted(zip(columns, order), key=lambda t: t[1])
310313
]
311-
reordered_result_in_dict: Dict[Label, Series] = {}
314+
reordered_result_in_dict: Dict[Label, "Series"] = {}
312315
idx = 0
313316

314-
reorder_mask = not isinstance(result, Series) and len(result.columns) > 1
317+
reorder_mask = not isinstance(result, ABCSeries) and len(result.columns) > 1
315318
for col, fun in func.items():
316319
s = result[col].dropna()
317320

pandas/core/series.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import pandas as pd
7171
from pandas.core import algorithms, base, generic, nanops, ops
7272
from pandas.core.accessor import CachedAccessor
73+
from pandas.core.aggregation import transform
7374
from pandas.core.arrays import ExtensionArray
7475
from pandas.core.arrays.categorical import CategoricalAccessor
7576
from pandas.core.arrays.sparse import SparseAccessor
@@ -4042,8 +4043,6 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):
40424043
def transform(
40434044
self, func: AggFuncType, axis: Axis = 0, *args, **kwargs
40444045
) -> FrameOrSeriesUnion:
4045-
from pandas.core.aggregation import transform
4046-
40474046
return transform(self, func, axis, *args, **kwargs)
40484047

40494048
def apply(self, func, convert_dtype=True, args=(), **kwds):

0 commit comments

Comments
 (0)