done
This commit is contained in:
		| @ -0,0 +1,15 @@ | ||||
| from pandas.core.groupby.generic import ( | ||||
|     DataFrameGroupBy as DataFrameGroupBy, | ||||
|     NamedAgg as NamedAgg, | ||||
|     SeriesGroupBy as SeriesGroupBy, | ||||
| ) | ||||
| from pandas.core.groupby.groupby import GroupBy as GroupBy | ||||
| from pandas.core.groupby.grouper import Grouper as Grouper | ||||
|  | ||||
| __all__ = [ | ||||
|     "DataFrameGroupBy", | ||||
|     "NamedAgg", | ||||
|     "SeriesGroupBy", | ||||
|     "GroupBy", | ||||
|     "Grouper", | ||||
| ] | ||||
| @ -0,0 +1,56 @@ | ||||
| from collections.abc import Hashable | ||||
| import dataclasses | ||||
| from typing import ( | ||||
|     Literal, | ||||
|     TypeAlias, | ||||
| ) | ||||
|  | ||||
| @dataclasses.dataclass(order=True, frozen=True) | ||||
| class OutputKey: | ||||
|     label: Hashable | ||||
|     position: int | ||||
|  | ||||
| ReductionKernelType: TypeAlias = Literal[ | ||||
|     "all", | ||||
|     "any", | ||||
|     "corrwith", | ||||
|     "count", | ||||
|     "first", | ||||
|     "idxmax", | ||||
|     "idxmin", | ||||
|     "last", | ||||
|     "max", | ||||
|     "mean", | ||||
|     "median", | ||||
|     "min", | ||||
|     "nunique", | ||||
|     "prod", | ||||
|     # as long as `quantile`'s signature accepts only | ||||
|     # a single quantile value, it's a reduction. | ||||
|     # GH#27526 might change that. | ||||
|     "quantile", | ||||
|     "sem", | ||||
|     "size", | ||||
|     "skew", | ||||
|     "std", | ||||
|     "sum", | ||||
|     "var", | ||||
| ] | ||||
|  | ||||
| TransformationKernelType: TypeAlias = Literal[ | ||||
|     "bfill", | ||||
|     "cumcount", | ||||
|     "cummax", | ||||
|     "cummin", | ||||
|     "cumprod", | ||||
|     "cumsum", | ||||
|     "diff", | ||||
|     "ffill", | ||||
|     "fillna", | ||||
|     "ngroup", | ||||
|     "pct_change", | ||||
|     "rank", | ||||
|     "shift", | ||||
| ] | ||||
|  | ||||
| TransformReductionListType: TypeAlias = ReductionKernelType | TransformationKernelType | ||||
| @ -0,0 +1,466 @@ | ||||
| from collections.abc import ( | ||||
|     Callable, | ||||
|     Hashable, | ||||
|     Iterable, | ||||
|     Iterator, | ||||
|     Sequence, | ||||
| ) | ||||
| from typing import ( | ||||
|     Any, | ||||
|     Concatenate, | ||||
|     Generic, | ||||
|     Literal, | ||||
|     NamedTuple, | ||||
|     Protocol, | ||||
|     TypeVar, | ||||
|     final, | ||||
|     overload, | ||||
| ) | ||||
|  | ||||
| from matplotlib.axes import Axes as PlotAxes | ||||
| import numpy as np | ||||
| from pandas.core.frame import DataFrame | ||||
| from pandas.core.groupby.base import TransformReductionListType | ||||
| from pandas.core.groupby.groupby import ( | ||||
|     GroupBy, | ||||
|     GroupByPlot, | ||||
| ) | ||||
| from pandas.core.series import Series | ||||
| from typing_extensions import ( | ||||
|     Self, | ||||
|     TypeAlias, | ||||
| ) | ||||
|  | ||||
| from pandas._libs.tslibs.timestamps import Timestamp | ||||
| from pandas._typing import ( | ||||
|     S2, | ||||
|     S3, | ||||
|     AggFuncTypeBase, | ||||
|     AggFuncTypeFrame, | ||||
|     ByT, | ||||
|     CorrelationMethod, | ||||
|     Dtype, | ||||
|     IndexLabel, | ||||
|     Level, | ||||
|     ListLike, | ||||
|     NsmallestNlargestKeep, | ||||
|     P, | ||||
|     Scalar, | ||||
|     TakeIndexer, | ||||
|     WindowingEngine, | ||||
|     WindowingEngineKwargs, | ||||
| ) | ||||
|  | ||||
| AggScalar: TypeAlias = str | Callable[..., Any] | ||||
|  | ||||
| class NamedAgg(NamedTuple): | ||||
|     column: str | ||||
|     aggfunc: AggScalar | ||||
|  | ||||
| class SeriesGroupBy(GroupBy[Series[S2]], Generic[S2, ByT]): | ||||
|     @overload | ||||
|     def aggregate(  # pyrefly: ignore | ||||
|         self, | ||||
|         func: Callable[Concatenate[Series[S2], P], S3], | ||||
|         /, | ||||
|         *args, | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         **kwargs, | ||||
|     ) -> Series[S3]: ... | ||||
|     @overload | ||||
|     def aggregate( | ||||
|         self, | ||||
|         func: Callable[[Series], S3], | ||||
|         *args, | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         **kwargs, | ||||
|     ) -> Series[S3]: ... | ||||
|     @overload | ||||
|     def aggregate( | ||||
|         self, | ||||
|         func: list[AggFuncTypeBase], | ||||
|         /, | ||||
|         *args, | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         **kwargs, | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def aggregate( | ||||
|         self, | ||||
|         func: AggFuncTypeBase | None = ..., | ||||
|         /, | ||||
|         *args, | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         **kwargs, | ||||
|     ) -> Series: ... | ||||
|     agg = aggregate | ||||
|     @overload | ||||
|     def transform( | ||||
|         self, | ||||
|         func: Callable[Concatenate[Series[S2], P], Series[S3]], | ||||
|         /, | ||||
|         *args: Any, | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         **kwargs: Any, | ||||
|     ) -> Series[S3]: ... | ||||
|     @overload | ||||
|     def transform( | ||||
|         self, | ||||
|         func: Callable, | ||||
|         *args: Any, | ||||
|         **kwargs: Any, | ||||
|     ) -> Series: ... | ||||
|     @overload | ||||
|     def transform( | ||||
|         self, func: TransformReductionListType, *args, **kwargs | ||||
|     ) -> Series: ... | ||||
|     def filter( | ||||
|         self, func: Callable | str, dropna: bool = ..., *args, **kwargs | ||||
|     ) -> Series: ... | ||||
|     def nunique(self, dropna: bool = ...) -> Series[int]: ... | ||||
|     # describe delegates to super() method but here it has keyword-only parameters | ||||
|     def describe(  # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||||
|         self, | ||||
|         *, | ||||
|         percentiles: Iterable[float] | None = ..., | ||||
|         include: Literal["all"] | list[Dtype] | None = ..., | ||||
|         exclude: list[Dtype] | None = ..., | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def value_counts( | ||||
|         self, | ||||
|         normalize: Literal[False] = ..., | ||||
|         sort: bool = ..., | ||||
|         ascending: bool = ..., | ||||
|         bins: int | Sequence[int] | None = ..., | ||||
|         dropna: bool = ..., | ||||
|     ) -> Series[int]: ... | ||||
|     @overload | ||||
|     def value_counts( | ||||
|         self, | ||||
|         normalize: Literal[True], | ||||
|         sort: bool = ..., | ||||
|         ascending: bool = ..., | ||||
|         bins: int | Sequence[int] | None = ..., | ||||
|         dropna: bool = ..., | ||||
|     ) -> Series[float]: ... | ||||
|     def take( | ||||
|         self, | ||||
|         indices: TakeIndexer, | ||||
|         **kwargs, | ||||
|     ) -> Series[S2]: ... | ||||
|     def skew( | ||||
|         self, | ||||
|         skipna: bool = True, | ||||
|         numeric_only: bool = False, | ||||
|         **kwargs, | ||||
|     ) -> Series: ... | ||||
|     @property | ||||
|     def plot(self) -> GroupByPlot[Self]: ... | ||||
|     def nlargest( | ||||
|         self, n: int = 5, keep: NsmallestNlargestKeep = "first" | ||||
|     ) -> Series[S2]: ... | ||||
|     def nsmallest( | ||||
|         self, n: int = 5, keep: NsmallestNlargestKeep = "first" | ||||
|     ) -> Series[S2]: ... | ||||
|     def idxmin(self, skipna: bool = True) -> Series: ... | ||||
|     def idxmax(self, skipna: bool = True) -> Series: ... | ||||
|     def corr( | ||||
|         self, | ||||
|         other: Series, | ||||
|         method: CorrelationMethod = ..., | ||||
|         min_periods: int | None = ..., | ||||
|     ) -> Series: ... | ||||
|     def cov( | ||||
|         self, | ||||
|         other: Series, | ||||
|         min_periods: int | None = None, | ||||
|         ddof: int | None = 1, | ||||
|     ) -> Series: ... | ||||
|     @property | ||||
|     def is_monotonic_increasing(self) -> Series[bool]: ... | ||||
|     @property | ||||
|     def is_monotonic_decreasing(self) -> Series[bool]: ... | ||||
|     def hist( | ||||
|         self, | ||||
|         by: IndexLabel | None = None, | ||||
|         ax: PlotAxes | None = None, | ||||
|         grid: bool = True, | ||||
|         xlabelsize: float | str | None = None, | ||||
|         xrot: float | None = None, | ||||
|         ylabelsize: float | str | None = None, | ||||
|         yrot: float | None = None, | ||||
|         figsize: tuple[float, float] | None = None, | ||||
|         bins: int | Sequence[int] = 10, | ||||
|         backend: str | None = None, | ||||
|         legend: bool = False, | ||||
|         **kwargs, | ||||
|     ) -> Series: ...  # Series[Axes] but this is not allowed | ||||
|     @property | ||||
|     def dtype(self) -> Series: ... | ||||
|     def unique(self) -> Series: ... | ||||
|     # Overrides that provide more precise return types over the GroupBy class | ||||
|     @final  # type: ignore[misc] | ||||
|     def __iter__(  # pyright: ignore[reportIncompatibleMethodOverride] | ||||
|         self, | ||||
|     ) -> Iterator[tuple[ByT, Series[S2]]]: ... | ||||
|  | ||||
| _TT = TypeVar("_TT", bound=Literal[True, False]) | ||||
|  | ||||
| # ty ignore needed because of https://github.com/astral-sh/ty/issues/157#issuecomment-3017337945 | ||||
| class DFCallable1(Protocol[P]):  # ty: ignore[invalid-argument-type] | ||||
|     def __call__( | ||||
|         self, df: DataFrame, /, *args: P.args, **kwargs: P.kwargs | ||||
|     ) -> Scalar | list | dict: ... | ||||
|  | ||||
| class DFCallable2(Protocol[P]):  # ty: ignore[invalid-argument-type] | ||||
|     def __call__( | ||||
|         self, df: DataFrame, /, *args: P.args, **kwargs: P.kwargs | ||||
|     ) -> DataFrame | Series: ... | ||||
|  | ||||
| class DFCallable3(Protocol[P]):  # ty: ignore[invalid-argument-type] | ||||
|     def __call__(self, df: Iterable, /, *args: P.args, **kwargs: P.kwargs) -> float: ... | ||||
|  | ||||
| class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT, _TT]): | ||||
|     # error: Overload 3 for "apply" will never be used because its parameters overlap overload 1 | ||||
|     @overload  # type: ignore[override] | ||||
|     def apply( | ||||
|         self, | ||||
|         func: DFCallable1[P], | ||||
|         /, | ||||
|         *args: P.args, | ||||
|         **kwargs: P.kwargs, | ||||
|     ) -> Series: ... | ||||
|     @overload | ||||
|     def apply( | ||||
|         self, | ||||
|         func: DFCallable2[P], | ||||
|         /, | ||||
|         *args: P.args, | ||||
|         **kwargs: P.kwargs, | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def apply( | ||||
|         self, | ||||
|         func: DFCallable3[P], | ||||
|         /, | ||||
|         *args: P.args, | ||||
|         **kwargs: P.kwargs, | ||||
|     ) -> DataFrame: ... | ||||
|     # error: overload 1 overlaps overload 2 because of different return types | ||||
|     @overload | ||||
|     def aggregate(self, func: Literal["size"]) -> Series: ...  # type: ignore[overload-overlap] | ||||
|     @overload | ||||
|     def aggregate( | ||||
|         self, | ||||
|         func: AggFuncTypeFrame | None = ..., | ||||
|         *args, | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         **kwargs, | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def aggregate( | ||||
|         self, | ||||
|         func: AggFuncTypeFrame | None = None, | ||||
|         /, | ||||
|         **kwargs, | ||||
|     ) -> DataFrame: ... | ||||
|     agg = aggregate | ||||
|     @overload | ||||
|     def transform( | ||||
|         self, | ||||
|         func: Callable[Concatenate[DataFrame, P], DataFrame], | ||||
|         *args: Any, | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         **kwargs: Any, | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def transform( | ||||
|         self, | ||||
|         func: Callable, | ||||
|         *args: Any, | ||||
|         **kwargs: Any, | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def transform( | ||||
|         self, func: TransformReductionListType, *args, **kwargs | ||||
|     ) -> DataFrame: ... | ||||
|     def filter( | ||||
|         self, func: Callable, dropna: bool = ..., *args, **kwargs | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def __getitem__(self, key: Scalar) -> SeriesGroupBy[Any, ByT]: ...  # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] | ||||
|     @overload | ||||
|     def __getitem__(  # pyright: ignore[reportIncompatibleMethodOverride] | ||||
|         self, key: Iterable[Hashable] | ||||
|     ) -> DataFrameGroupBy[ByT, _TT]: ... | ||||
|     def nunique(self, dropna: bool = True) -> DataFrame: ... | ||||
|     def idxmax( | ||||
|         self, | ||||
|         skipna: bool = True, | ||||
|         numeric_only: bool = False, | ||||
|     ) -> DataFrame: ... | ||||
|     def idxmin( | ||||
|         self, | ||||
|         skipna: bool = True, | ||||
|         numeric_only: bool = False, | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def boxplot( | ||||
|         self, | ||||
|         subplots: Literal[True] = ..., | ||||
|         column: IndexLabel | None = ..., | ||||
|         fontsize: float | str | None = ..., | ||||
|         rot: float = ..., | ||||
|         grid: bool = ..., | ||||
|         ax: PlotAxes | None = ..., | ||||
|         figsize: tuple[float, float] | None = ..., | ||||
|         layout: tuple[int, int] | None = ..., | ||||
|         sharex: bool = ..., | ||||
|         sharey: bool = ..., | ||||
|         backend: str | None = ..., | ||||
|         **kwargs, | ||||
|     ) -> Series: ...  # Series[PlotAxes] but this is not allowed | ||||
|     @overload | ||||
|     def boxplot( | ||||
|         self, | ||||
|         subplots: Literal[False], | ||||
|         column: IndexLabel | None = ..., | ||||
|         fontsize: float | str | None = ..., | ||||
|         rot: float = ..., | ||||
|         grid: bool = ..., | ||||
|         ax: PlotAxes | None = ..., | ||||
|         figsize: tuple[float, float] | None = ..., | ||||
|         layout: tuple[int, int] | None = ..., | ||||
|         sharex: bool = ..., | ||||
|         sharey: bool = ..., | ||||
|         backend: str | None = ..., | ||||
|         **kwargs, | ||||
|     ) -> PlotAxes: ... | ||||
|     @overload | ||||
|     def boxplot( | ||||
|         self, | ||||
|         subplots: bool, | ||||
|         column: IndexLabel | None = ..., | ||||
|         fontsize: float | str | None = ..., | ||||
|         rot: float = ..., | ||||
|         grid: bool = ..., | ||||
|         ax: PlotAxes | None = ..., | ||||
|         figsize: tuple[float, float] | None = ..., | ||||
|         layout: tuple[int, int] | None = ..., | ||||
|         sharex: bool = ..., | ||||
|         sharey: bool = ..., | ||||
|         backend: str | None = ..., | ||||
|         **kwargs, | ||||
|     ) -> PlotAxes | Series: ...  # Series[PlotAxes] | ||||
|     @overload | ||||
|     def value_counts( | ||||
|         self: DataFrameGroupBy[ByT, Literal[True]], | ||||
|         subset: ListLike | None = ..., | ||||
|         normalize: Literal[False] = ..., | ||||
|         sort: bool = ..., | ||||
|         ascending: bool = ..., | ||||
|         dropna: bool = ..., | ||||
|     ) -> Series[int]: ... | ||||
|     @overload | ||||
|     def value_counts( | ||||
|         self: DataFrameGroupBy[ByT, Literal[True]], | ||||
|         subset: ListLike | None, | ||||
|         normalize: Literal[True], | ||||
|         sort: bool = ..., | ||||
|         ascending: bool = ..., | ||||
|         dropna: bool = ..., | ||||
|     ) -> Series[float]: ... | ||||
|     @overload | ||||
|     def value_counts( | ||||
|         self: DataFrameGroupBy[ByT, Literal[False]], | ||||
|         subset: ListLike | None = ..., | ||||
|         normalize: Literal[False] = ..., | ||||
|         sort: bool = ..., | ||||
|         ascending: bool = ..., | ||||
|         dropna: bool = ..., | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def value_counts( | ||||
|         self: DataFrameGroupBy[ByT, Literal[False]], | ||||
|         subset: ListLike | None, | ||||
|         normalize: Literal[True], | ||||
|         sort: bool = ..., | ||||
|         ascending: bool = ..., | ||||
|         dropna: bool = ..., | ||||
|     ) -> DataFrame: ... | ||||
|     def take(self, indices: TakeIndexer, **kwargs) -> DataFrame: ... | ||||
|     @overload | ||||
|     def skew( | ||||
|         self, | ||||
|         skipna: bool = ..., | ||||
|         numeric_only: bool = ..., | ||||
|         *, | ||||
|         level: Level, | ||||
|         **kwargs, | ||||
|     ) -> DataFrame: ... | ||||
|     @overload | ||||
|     def skew( | ||||
|         self, | ||||
|         skipna: bool = ..., | ||||
|         numeric_only: bool = ..., | ||||
|         *, | ||||
|         level: None = ..., | ||||
|         **kwargs, | ||||
|     ) -> Series: ... | ||||
|     @property | ||||
|     def plot(self) -> GroupByPlot[Self]: ... | ||||
|     def corr( | ||||
|         self, | ||||
|         method: str | Callable[[np.ndarray, np.ndarray], float] = ..., | ||||
|         min_periods: int = ..., | ||||
|         numeric_only: bool = False, | ||||
|     ) -> DataFrame: ... | ||||
|     def cov( | ||||
|         self, | ||||
|         min_periods: int | None = ..., | ||||
|         ddof: int | None = 1, | ||||
|         numeric_only: bool = False, | ||||
|     ) -> DataFrame: ... | ||||
|     def hist( | ||||
|         self, | ||||
|         column: IndexLabel | None = None, | ||||
|         by: IndexLabel | None = None, | ||||
|         grid: bool = True, | ||||
|         xlabelsize: float | str | None = None, | ||||
|         xrot: float | None = None, | ||||
|         ylabelsize: float | str | None = None, | ||||
|         yrot: float | None = None, | ||||
|         ax: PlotAxes | None = None, | ||||
|         sharex: bool = False, | ||||
|         sharey: bool = False, | ||||
|         figsize: tuple[float, float] | None = None, | ||||
|         layout: tuple[int, int] | None = None, | ||||
|         bins: int | Sequence[int] = 10, | ||||
|         backend: str | None = None, | ||||
|         legend: bool = False, | ||||
|         **kwargs, | ||||
|     ) -> Series: ...  # Series[Axes] but this is not allowed | ||||
|     @property | ||||
|     def dtypes(self) -> Series: ... | ||||
|     def __getattr__(self, name: str) -> SeriesGroupBy[Any, ByT]: ... | ||||
|     # Overrides that provide more precise return types over the GroupBy class | ||||
|     @final  # type: ignore[misc] | ||||
|     def __iter__(  # pyright: ignore[reportIncompatibleMethodOverride] | ||||
|         self, | ||||
|     ) -> Iterator[tuple[ByT, DataFrame]]: ... | ||||
|     @overload | ||||
|     def size(self: DataFrameGroupBy[ByT, Literal[True]]) -> Series[int]: ... | ||||
|     @overload | ||||
|     def size(self: DataFrameGroupBy[ByT, Literal[False]]) -> DataFrame: ... | ||||
|     @overload | ||||
|     def size(self: DataFrameGroupBy[Timestamp, Literal[True]]) -> Series[int]: ... | ||||
|     @overload | ||||
|     def size(self: DataFrameGroupBy[Timestamp, Literal[False]]) -> DataFrame: ... | ||||
| @ -0,0 +1,393 @@ | ||||
| from collections.abc import ( | ||||
|     Callable, | ||||
|     Hashable, | ||||
|     Iterable, | ||||
|     Iterator, | ||||
|     Sequence, | ||||
| ) | ||||
| import datetime as dt | ||||
| from typing import ( | ||||
|     Any, | ||||
|     Generic, | ||||
|     Literal, | ||||
|     TypeVar, | ||||
|     final, | ||||
|     overload, | ||||
| ) | ||||
|  | ||||
| import numpy as np | ||||
| from pandas.core.base import SelectionMixin | ||||
| from pandas.core.frame import DataFrame | ||||
| from pandas.core.groupby import ( | ||||
|     generic, | ||||
| ) | ||||
| from pandas.core.groupby.indexing import ( | ||||
|     GroupByIndexingMixin, | ||||
|     GroupByNthSelector, | ||||
| ) | ||||
| from pandas.core.indexers import BaseIndexer | ||||
| from pandas.core.indexes.api import Index | ||||
| from pandas.core.resample import ( | ||||
|     DatetimeIndexResamplerGroupby, | ||||
|     PeriodIndexResamplerGroupby, | ||||
|     TimedeltaIndexResamplerGroupby, | ||||
| ) | ||||
| from pandas.core.series import Series | ||||
| from pandas.core.window import ( | ||||
|     ExpandingGroupby, | ||||
|     ExponentialMovingWindowGroupby, | ||||
|     RollingGroupby, | ||||
| ) | ||||
| from typing_extensions import ( | ||||
|     Concatenate, | ||||
|     Self, | ||||
|     TypeAlias, | ||||
| ) | ||||
|  | ||||
| from pandas._libs.lib import _NoDefaultDoNotUse | ||||
| from pandas._libs.tslibs import BaseOffset | ||||
| from pandas._typing import ( | ||||
|     S1, | ||||
|     AnyArrayLike, | ||||
|     Axis, | ||||
|     AxisInt, | ||||
|     CalculationMethod, | ||||
|     Dtype, | ||||
|     Frequency, | ||||
|     IndexLabel, | ||||
|     IntervalClosedType, | ||||
|     MaskType, | ||||
|     NDFrameT, | ||||
|     P, | ||||
|     RandomState, | ||||
|     Scalar, | ||||
|     T, | ||||
|     TimedeltaConvertibleTypes, | ||||
|     TimeGrouperOrigin, | ||||
|     TimestampConvention, | ||||
|     TimestampConvertibleTypes, | ||||
|     WindowingEngine, | ||||
|     WindowingEngineKwargs, | ||||
|     npt, | ||||
| ) | ||||
|  | ||||
| from pandas.plotting import PlotAccessor | ||||
|  | ||||
| _ResamplerGroupBy: TypeAlias = ( | ||||
|     DatetimeIndexResamplerGroupby[NDFrameT]  # ty: ignore[invalid-argument-type] | ||||
|     | PeriodIndexResamplerGroupby[NDFrameT]  # ty: ignore[invalid-argument-type] | ||||
|     | TimedeltaIndexResamplerGroupby[NDFrameT]  # ty: ignore[invalid-argument-type] | ||||
| ) | ||||
|  | ||||
| class GroupBy(BaseGroupBy[NDFrameT]): | ||||
|     def __getattr__(self, attr: str) -> Any: ... | ||||
|     def apply(self, func: Callable | str, *args, **kwargs) -> NDFrameT: ... | ||||
|     @final | ||||
|     @overload | ||||
|     def any(self: GroupBy[Series], skipna: bool = ...) -> Series[bool]: ... | ||||
|     @overload | ||||
|     def any(self: GroupBy[DataFrame], skipna: bool = ...) -> DataFrame: ... | ||||
|     @final | ||||
|     @overload | ||||
|     def all(self: GroupBy[Series], skipna: bool = ...) -> Series[bool]: ... | ||||
|     @overload | ||||
|     def all(self: GroupBy[DataFrame], skipna: bool = ...) -> DataFrame: ... | ||||
|     @final | ||||
|     @overload | ||||
|     def count(self: GroupBy[Series]) -> Series[int]: ... | ||||
|     @overload | ||||
|     def count(self: GroupBy[DataFrame]) -> DataFrame: ... | ||||
|     @final | ||||
|     def mean( | ||||
|         self, | ||||
|         numeric_only: bool = False, | ||||
|         engine: WindowingEngine = None, | ||||
|         engine_kwargs: WindowingEngineKwargs = None, | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def median(self, numeric_only: bool = False) -> NDFrameT: ... | ||||
|     @final | ||||
|     @overload | ||||
|     def std( | ||||
|         self: GroupBy[Series], | ||||
|         ddof: int = ..., | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         numeric_only: bool = ..., | ||||
|     ) -> Series[float]: ... | ||||
|     @overload | ||||
|     def std( | ||||
|         self: GroupBy[DataFrame], | ||||
|         ddof: int = ..., | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         numeric_only: bool = ..., | ||||
|     ) -> DataFrame: ... | ||||
|     @final | ||||
|     @overload | ||||
|     def var( | ||||
|         self: GroupBy[Series], | ||||
|         ddof: int = ..., | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         numeric_only: bool = ..., | ||||
|     ) -> Series[float]: ... | ||||
|     @overload | ||||
|     def var( | ||||
|         self: GroupBy[DataFrame], | ||||
|         ddof: int = ..., | ||||
|         engine: WindowingEngine = ..., | ||||
|         engine_kwargs: WindowingEngineKwargs = ..., | ||||
|         numeric_only: bool = ..., | ||||
|     ) -> DataFrame: ... | ||||
|     @final | ||||
|     @overload | ||||
|     def sem( | ||||
|         self: GroupBy[Series], ddof: int = ..., numeric_only: bool = ... | ||||
|     ) -> Series[float]: ... | ||||
|     @overload | ||||
|     def sem( | ||||
|         self: GroupBy[DataFrame], ddof: int = ..., numeric_only: bool = ... | ||||
|     ) -> DataFrame: ... | ||||
|     def size(self: GroupBy[Series]) -> Series[int]: ... | ||||
|     @final | ||||
|     def sum( | ||||
|         self, | ||||
|         numeric_only: bool = False, | ||||
|         min_count: int = 0, | ||||
|         engine: WindowingEngine = None, | ||||
|         engine_kwargs: WindowingEngineKwargs = None, | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def prod(self, numeric_only: bool = False, min_count: int = 0) -> NDFrameT: ... | ||||
|     @final | ||||
|     def min( | ||||
|         self, | ||||
|         numeric_only: bool = False, | ||||
|         min_count: int = -1, | ||||
|         engine: WindowingEngine = None, | ||||
|         engine_kwargs: WindowingEngineKwargs = None, | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def max( | ||||
|         self, | ||||
|         numeric_only: bool = False, | ||||
|         min_count: int = -1, | ||||
|         engine: WindowingEngine = None, | ||||
|         engine_kwargs: WindowingEngineKwargs = None, | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def first( | ||||
|         self, numeric_only: bool = False, min_count: int = -1, skipna: bool = True | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def last( | ||||
|         self, numeric_only: bool = False, min_count: int = -1, skipna: bool = True | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def ohlc(self) -> DataFrame: ... | ||||
|     def describe( | ||||
|         self, | ||||
|         percentiles: Iterable[float] | None = ..., | ||||
|         include: Literal["all"] | list[Dtype] | None = ..., | ||||
|         exclude: list[Dtype] | None = ..., | ||||
|     ) -> DataFrame: ... | ||||
|     @final | ||||
|     def resample( | ||||
|         self, | ||||
|         rule: Frequency | dt.timedelta, | ||||
|         how: str | None = ..., | ||||
|         fill_method: str | None = ..., | ||||
|         limit: int | None = ..., | ||||
|         kind: str | None = ..., | ||||
|         on: Hashable | None = ..., | ||||
|         *, | ||||
|         closed: Literal["left", "right"] | None = ..., | ||||
|         label: Literal["left", "right"] | None = ..., | ||||
|         axis: Axis = ..., | ||||
|         convention: TimestampConvention | None = ..., | ||||
|         origin: TimeGrouperOrigin | TimestampConvertibleTypes = ..., | ||||
|         offset: TimedeltaConvertibleTypes | None = ..., | ||||
|         group_keys: bool = ..., | ||||
|         **kwargs, | ||||
|     ) -> _ResamplerGroupBy[NDFrameT]: ... | ||||
|     @final | ||||
|     def rolling( | ||||
|         self, | ||||
|         window: int | dt.timedelta | str | BaseOffset | BaseIndexer | None = ..., | ||||
|         min_periods: int | None = None, | ||||
|         center: bool | None = False, | ||||
|         win_type: str | None = None, | ||||
|         axis: Axis = 0, | ||||
|         on: str | Index | None = None, | ||||
|         closed: IntervalClosedType | None = None, | ||||
|         method: CalculationMethod = "single", | ||||
|         *, | ||||
|         selection: IndexLabel | None = None, | ||||
|     ) -> RollingGroupby[NDFrameT]: ... | ||||
|     @final | ||||
|     def expanding( | ||||
|         self, | ||||
|         min_periods: int = ..., | ||||
|         axis: Axis = ..., | ||||
|         method: CalculationMethod = ..., | ||||
|         selection: IndexLabel | None = ..., | ||||
|     ) -> ExpandingGroupby[NDFrameT]: ... | ||||
|     @final | ||||
|     def ewm( | ||||
|         self, | ||||
|         com: float | None = ..., | ||||
|         span: float | None = ..., | ||||
|         halflife: TimedeltaConvertibleTypes | None = ..., | ||||
|         alpha: float | None = ..., | ||||
|         min_periods: int | None = ..., | ||||
|         adjust: bool = ..., | ||||
|         ignore_na: bool = ..., | ||||
|         axis: Axis = ..., | ||||
|         times: str | np.ndarray | Series | np.timedelta64 | None = ..., | ||||
|         method: CalculationMethod = ..., | ||||
|         *, | ||||
|         selection: IndexLabel | None = ..., | ||||
|     ) -> ExponentialMovingWindowGroupby[NDFrameT]: ... | ||||
|     @final | ||||
|     def ffill(self, limit: int | None = ...) -> NDFrameT: ... | ||||
|     @final | ||||
|     def bfill(self, limit: int | None = ...) -> NDFrameT: ... | ||||
|     @final | ||||
|     @property | ||||
|     def nth(self) -> GroupByNthSelector[Self]: ... | ||||
|     @final | ||||
|     def quantile( | ||||
|         self, | ||||
|         q: float | AnyArrayLike = 0.5, | ||||
|         interpolation: str = "linear", | ||||
|         numeric_only: bool = False, | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def ngroup(self, ascending: bool = True) -> Series[int]: ... | ||||
|     @final | ||||
|     def cumcount(self, ascending: bool = True) -> Series[int]: ... | ||||
|     @final | ||||
|     def rank( | ||||
|         self, | ||||
|         method: str = "average", | ||||
|         ascending: bool = True, | ||||
|         na_option: str = "keep", | ||||
|         pct: bool = False, | ||||
|         axis: AxisInt | _NoDefaultDoNotUse = 0, | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def cumprod( | ||||
|         self, axis: Axis | _NoDefaultDoNotUse = ..., *args, **kwargs | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def cumsum( | ||||
|         self, axis: Axis | _NoDefaultDoNotUse = ..., *args, **kwargs | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def cummin( | ||||
|         self, | ||||
|         axis: AxisInt | _NoDefaultDoNotUse = ..., | ||||
|         numeric_only: bool = ..., | ||||
|         **kwargs, | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def cummax( | ||||
|         self, | ||||
|         axis: AxisInt | _NoDefaultDoNotUse = ..., | ||||
|         numeric_only: bool = ..., | ||||
|         **kwargs, | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def shift( | ||||
|         self, | ||||
|         periods: int | Sequence[int] = 1, | ||||
|         freq: Frequency | None = ..., | ||||
|         axis: Axis | _NoDefaultDoNotUse = 0, | ||||
|         fill_value=..., | ||||
|         suffix: str | None = ..., | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def diff( | ||||
|         self, periods: int = 1, axis: AxisInt | _NoDefaultDoNotUse = 0 | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def pct_change( | ||||
|         self, | ||||
|         periods: int = ..., | ||||
|         fill_method: Literal["bfill", "ffill"] | None | _NoDefaultDoNotUse = ..., | ||||
|         limit: int | None | _NoDefaultDoNotUse = ..., | ||||
|         freq=..., | ||||
|         axis: Axis | _NoDefaultDoNotUse = ..., | ||||
|     ) -> NDFrameT: ... | ||||
|     @final | ||||
|     def head(self, n: int = ...) -> NDFrameT: ... | ||||
|     @final | ||||
|     def tail(self, n: int = ...) -> NDFrameT: ... | ||||
|     @final | ||||
|     def sample( | ||||
|         self, | ||||
|         n: int | None = None, | ||||
|         frac: float | None = None, | ||||
|         replace: bool = False, | ||||
|         weights: Sequence | Series | None = ..., | ||||
|         random_state: RandomState | None = ..., | ||||
|     ) -> NDFrameT: ... | ||||
|  | ||||
| _GroupByT = TypeVar("_GroupByT", bound=GroupBy) | ||||
|  | ||||
| # GroupByPlot does not really inherit from PlotAccessor but it delegates | ||||
| # to it using __call__ and __getattr__. We lie here to avoid repeating the | ||||
| # whole stub of PlotAccessor | ||||
| @final | ||||
| class GroupByPlot(PlotAccessor, Generic[_GroupByT]): | ||||
|     def __init__(self, groupby: _GroupByT) -> None: ... | ||||
|     # The following methods are inherited from the fake parent class PlotAccessor | ||||
|     # def __call__(self, *args, **kwargs): ... | ||||
|     # def __getattr__(self, name: str): ... | ||||
|  | ||||
| class BaseGroupBy(SelectionMixin[NDFrameT], GroupByIndexingMixin): | ||||
|     @final | ||||
|     def __len__(self) -> int: ... | ||||
|     @final | ||||
|     def __repr__(self) -> str: ...  # noqa: PYI029 __repr__ here is final | ||||
|     @final | ||||
|     @property | ||||
|     def groups(self) -> dict[Hashable, Index]: ... | ||||
|     @final | ||||
|     @property | ||||
|     def ngroups(self) -> int: ... | ||||
|     @final | ||||
|     @property | ||||
|     def indices(self) -> dict[Hashable, Index | npt.NDArray[np.int_] | list[int]]: ... | ||||
|     @overload | ||||
|     def pipe( | ||||
|         self, | ||||
|         func: Callable[Concatenate[Self, P], T], | ||||
|         *args: P.args, | ||||
|         **kwargs: P.kwargs, | ||||
|     ) -> T: ... | ||||
|     @overload | ||||
|     def pipe( | ||||
|         self, | ||||
|         func: tuple[Callable[..., T], str], | ||||
|         *args: Any, | ||||
|         **kwargs: Any, | ||||
|     ) -> T: ... | ||||
|     @final | ||||
|     def get_group(self, name) -> NDFrameT: ... | ||||
|     @final | ||||
|     def __iter__(self) -> Iterator[tuple[Hashable, NDFrameT]]: ... | ||||
|     @overload | ||||
|     def __getitem__(self: BaseGroupBy[DataFrame], key: Scalar) -> generic.SeriesGroupBy: ...  # type: ignore[overload-overlap] # pyright: ignore[reportOverlappingOverload] | ||||
|     @overload | ||||
|     def __getitem__( | ||||
|         self: BaseGroupBy[DataFrame], key: Iterable[Hashable] | ||||
|     ) -> generic.DataFrameGroupBy: ... | ||||
|     @overload | ||||
|     def __getitem__( | ||||
|         self: BaseGroupBy[Series[S1]], | ||||
|         idx: list[str] | Index | Series[S1] | MaskType | tuple[Hashable | slice, ...], | ||||
|     ) -> generic.SeriesGroupBy: ... | ||||
|     @overload | ||||
|     def __getitem__(self: BaseGroupBy[Series[S1]], idx: Scalar) -> S1: ... | ||||
| @ -0,0 +1,74 @@ | ||||
| from collections.abc import ( | ||||
|     Hashable, | ||||
|     Iterator, | ||||
| ) | ||||
| from typing import ( | ||||
|     final, | ||||
|     overload, | ||||
| ) | ||||
|  | ||||
| import numpy as np | ||||
| from pandas import ( | ||||
|     DataFrame, | ||||
|     Index, | ||||
|     Series, | ||||
| ) | ||||
| from pandas.core.resample import TimeGrouper | ||||
| from typing_extensions import Self | ||||
|  | ||||
| from pandas._libs.lib import _NoDefaultDoNotUse | ||||
| from pandas._typing import ( | ||||
|     ArrayLike, | ||||
|     Axis, | ||||
|     Frequency, | ||||
|     Incomplete, | ||||
|     KeysArgType, | ||||
|     Level, | ||||
|     ListLikeHashable, | ||||
|     npt, | ||||
| ) | ||||
| from pandas.util._decorators import cache_readonly | ||||
|  | ||||
| class Grouper: | ||||
|     key: KeysArgType | None | ||||
|     level: Level | ListLikeHashable[Level] | None | ||||
|     freq: Frequency | None | ||||
|     axis: Axis | ||||
|     sort: bool | ||||
|     dropna: bool | ||||
|     binner: Incomplete | ||||
|     @overload | ||||
|     def __new__( | ||||
|         cls, | ||||
|         key: KeysArgType | None = ..., | ||||
|         level: Level | ListLikeHashable[Level] | None = ..., | ||||
|         axis: Axis | _NoDefaultDoNotUse = ..., | ||||
|         sort: bool = ..., | ||||
|         dropna: bool = ..., | ||||
|     ) -> Self: ... | ||||
|     @overload | ||||
|     def __new__(cls, *args, freq: Frequency, **kwargs) -> TimeGrouper: ... | ||||
|     @final | ||||
|     def __repr__(self) -> str: ...  # noqa: PYI029 __repr__ here is final | ||||
|  | ||||
| @final | ||||
| class Grouping: | ||||
|     level: Level | None | ||||
|     obj: DataFrame | Series | None | ||||
|     in_axis: bool | ||||
|     grouping_vector: Incomplete | ||||
|     def __iter__(self) -> Iterator[Hashable]: ... | ||||
|     @cache_readonly | ||||
|     def name(self) -> Hashable: ... | ||||
|     @cache_readonly | ||||
|     def ngroups(self) -> int: ... | ||||
|     @cache_readonly | ||||
|     def indices(self) -> dict[Hashable, npt.NDArray[np.intp]]: ... | ||||
|     @property | ||||
|     def codes(self) -> npt.NDArray[np.signedinteger]: ... | ||||
|     @cache_readonly | ||||
|     def group_arraylike(self) -> ArrayLike: ... | ||||
|     @cache_readonly | ||||
|     def result_index(self) -> Index: ... | ||||
|     @cache_readonly | ||||
|     def group_index(self) -> Index: ... | ||||
| @ -0,0 +1,32 @@ | ||||
| from typing import ( | ||||
|     Any, | ||||
|     Generic, | ||||
|     Literal, | ||||
|     TypeVar, | ||||
| ) | ||||
|  | ||||
| from pandas import ( | ||||
|     DataFrame, | ||||
|     Series, | ||||
| ) | ||||
| from pandas.core.groupby import groupby | ||||
|  | ||||
| from pandas._typing import PositionalIndexer | ||||
|  | ||||
| _GroupByT = TypeVar("_GroupByT", bound=groupby.GroupBy[Any]) | ||||
|  | ||||
| class GroupByIndexingMixin: ... | ||||
|  | ||||
| class GroupByPositionalSelector: | ||||
|     groupby_object: groupby.GroupBy | ||||
|     def __getitem__(self, arg: PositionalIndexer | tuple) -> DataFrame | Series: ... | ||||
|  | ||||
| class GroupByNthSelector(Generic[_GroupByT]): | ||||
|     groupby_object: _GroupByT | ||||
|  | ||||
|     def __call__( | ||||
|         self, | ||||
|         n: PositionalIndexer | tuple, | ||||
|         dropna: Literal["any", "all", None] = ..., | ||||
|     ) -> DataFrame | Series: ... | ||||
|     def __getitem__(self, n: PositionalIndexer | tuple) -> DataFrame | Series: ... | ||||
							
								
								
									
										103
									
								
								lib/python3.11/site-packages/pandas-stubs/core/groupby/ops.pyi
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								lib/python3.11/site-packages/pandas-stubs/core/groupby/ops.pyi
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,103 @@ | ||||
| from collections.abc import ( | ||||
|     Callable, | ||||
|     Hashable, | ||||
|     Iterator, | ||||
| ) | ||||
| from typing import ( | ||||
|     Generic, | ||||
|     final, | ||||
| ) | ||||
|  | ||||
| import numpy as np | ||||
| from pandas import ( | ||||
|     Index, | ||||
|     Series, | ||||
| ) | ||||
| from pandas.core.groupby import grouper | ||||
|  | ||||
| from pandas._typing import ( | ||||
|     ArrayLike, | ||||
|     AxisInt, | ||||
|     Incomplete, | ||||
|     NDFrameT, | ||||
|     Shape, | ||||
|     T, | ||||
|     npt, | ||||
| ) | ||||
| from pandas.util._decorators import cache_readonly | ||||
|  | ||||
| class BaseGrouper: | ||||
|     axis: Index | ||||
|     dropna: bool | ||||
|     @property | ||||
|     def groupings(self) -> list[grouper.Grouping]: ... | ||||
|     @property | ||||
|     def shape(self) -> Shape: ... | ||||
|     def __iter__(self) -> Iterator: ... | ||||
|     @property | ||||
|     def nkeys(self) -> int: ... | ||||
|     def get_iterator( | ||||
|         self, data: NDFrameT, axis: AxisInt = ... | ||||
|     ) -> Iterator[tuple[Hashable, NDFrameT]]: ... | ||||
|     @final | ||||
|     @cache_readonly | ||||
|     def group_keys_seq(self): ... | ||||
|     @cache_readonly | ||||
|     def indices(self) -> dict[Hashable, npt.NDArray[np.intp]]: ... | ||||
|     @final | ||||
|     def result_ilocs(self) -> npt.NDArray[np.intp]: ... | ||||
|     @final | ||||
|     @property | ||||
|     def codes(self) -> list[npt.NDArray[np.signedinteger]]: ... | ||||
|     @property | ||||
|     def levels(self) -> list[Index]: ... | ||||
|     @property | ||||
|     def names(self) -> list: ... | ||||
|     @final | ||||
|     def size(self) -> Series: ... | ||||
|     @cache_readonly | ||||
|     def groups(self) -> dict[Hashable, np.ndarray]: ... | ||||
|     @final | ||||
|     @cache_readonly | ||||
|     def is_monotonic(self) -> bool: ... | ||||
|     @final | ||||
|     @cache_readonly | ||||
|     def has_dropped_na(self) -> bool: ... | ||||
|     @cache_readonly | ||||
|     def group_info(self) -> tuple[npt.NDArray[np.intp], npt.NDArray[np.intp], int]: ... | ||||
|     @cache_readonly | ||||
|     def codes_info(self) -> npt.NDArray[np.intp]: ... | ||||
|     @final | ||||
|     @cache_readonly | ||||
|     def ngroups(self) -> int: ... | ||||
|     @property | ||||
|     def reconstructed_codes(self) -> list[npt.NDArray[np.intp]]: ... | ||||
|     @cache_readonly | ||||
|     def result_index(self) -> Index: ... | ||||
|     @final | ||||
|     def get_group_levels(self) -> list[ArrayLike]: ... | ||||
|     @final | ||||
|     def agg_series( | ||||
|         self, | ||||
|         obj: Series, | ||||
|         func: Callable[[Series], object], | ||||
|         preserve_dtype: bool = ..., | ||||
|     ) -> ArrayLike: ... | ||||
|     @final | ||||
|     def apply_groupwise( | ||||
|         self, f: Callable[[NDFrameT], T], data: NDFrameT, axis: AxisInt = ... | ||||
|     ) -> tuple[list[T], bool]: ... | ||||
|  | ||||
| class BinGrouper(BaseGrouper): | ||||
|     bins: npt.NDArray[np.int64] | ||||
|     binlabels: Index | ||||
|     indexer: npt.NDArray[np.intp] | ||||
|     @cache_readonly | ||||
|     def indices(self) -> dict[Incomplete, list[int]]: ...  # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride] | ||||
|  | ||||
| class DataSplitter(Generic[NDFrameT]): | ||||
|     data: NDFrameT | ||||
|     labels: npt.NDArray[np.intp] | ||||
|     ngroups: int | ||||
|     axis: AxisInt | ||||
|     def __iter__(self) -> Iterator[NDFrameT]: ... | ||||
		Reference in New Issue
	
	Block a user