Skip to content

CLN: Avoid importing Series in core.aggregation #36612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pandas/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from collections import defaultdict
from functools import partial
from typing import (
TYPE_CHECKING,
Any,
Callable,
DefaultDict,
Expand All @@ -26,7 +27,9 @@
from pandas.core.base import SpecificationError
import pandas.core.common as com
from pandas.core.indexes.api import Index
from pandas.core.series import Series

if TYPE_CHECKING:
from pandas.core.series import Series


def reconstruct_func(
Expand Down Expand Up @@ -281,7 +284,7 @@ def relabel_result(
func: Dict[str, List[Union[Callable, str]]],
columns: Iterable[Label],
order: Iterable[int],
) -> Dict[Label, Series]:
) -> Dict[Label, "Series"]:
"""
Internal function to reorder result if relabelling is True for
dataframe.agg, and return the reordered result in dict.
Expand All @@ -308,10 +311,10 @@ def relabel_result(
reordered_indexes = [
pair[0] for pair in sorted(zip(columns, order), key=lambda t: t[1])
]
reordered_result_in_dict: Dict[Label, Series] = {}
reordered_result_in_dict: Dict[Label, "Series"] = {}
idx = 0

reorder_mask = not isinstance(result, Series) and len(result.columns) > 1
reorder_mask = not isinstance(result, ABCSeries) and len(result.columns) > 1
for col, fun in func.items():
s = result[col].dropna()

Expand Down
3 changes: 1 addition & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import pandas as pd
from pandas.core import algorithms, base, generic, nanops, ops
from pandas.core.accessor import CachedAccessor
from pandas.core.aggregation import transform
from pandas.core.arrays import ExtensionArray
from pandas.core.arrays.categorical import CategoricalAccessor
from pandas.core.arrays.sparse import SparseAccessor
Expand Down Expand Up @@ -4042,8 +4043,6 @@ def aggregate(self, func=None, axis=0, *args, **kwargs):
def transform(
self, func: AggFuncType, axis: Axis = 0, *args, **kwargs
) -> FrameOrSeriesUnion:
from pandas.core.aggregation import transform

return transform(self, func, axis, *args, **kwargs)

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