Skip to content

ENH: Improve Roling, Expanding and EWM #297

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 10 commits into from
Sep 19, 2022
25 changes: 21 additions & 4 deletions pandas-stubs/_typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,17 @@ FuncType = Callable[..., Any]
F = TypeVar("F", bound=FuncType)
HashableT = TypeVar("HashableT", bound=Hashable)

AggFuncTypeBase = Union[Callable, str]
AggFuncTypeDict = dict[Hashable, Union[AggFuncTypeBase, list[AggFuncTypeBase]]]
AggFuncType = Union[
AggFuncTypeBase = Union[Callable, str, np.ufunc]
AggFuncTypeDictSeries = dict[Hashable, AggFuncTypeBase]
AggFuncTypeDictFrame = dict[Hashable, Union[AggFuncTypeBase, list[AggFuncTypeBase]]]
AggFuncTypeSeriesToFrame = Union[
list[AggFuncTypeBase],
AggFuncTypeDictSeries,
]
AggFuncTypeFrame = Union[
AggFuncTypeBase,
list[AggFuncTypeBase],
AggFuncTypeDict,
AggFuncTypeDictFrame,
]

num = complex
Expand Down Expand Up @@ -264,6 +269,18 @@ FileWriteMode = Literal[
]
ColspaceArgType = str | int | Sequence[int | str] | Mapping[Hashable, str | int]

# Windowing rank methods
WindowingRankType = Literal["average", "min", "max"]
WindowingEngine = Union[Literal["cython", "numba"], None]

class _WindowingNumbaKwargs(TypedDict, total=False):
nopython: bool
nogil: bool
parallel: bool

WindowingEngineKwargs = Union[_WindowingNumbaKwargs, None]
QuantileInterpolation = Literal["linear", "lower", "higher", "midpoint", "nearest"]

class StyleExportDict(TypedDict, total=False):
apply: Any
table_attributes: Any
Expand Down
43 changes: 26 additions & 17 deletions pandas-stubs/core/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ from pandas.core.indexing import (
)
from pandas.core.resample import Resampler
from pandas.core.series import Series
from pandas.core.window import (
Expanding,
ExponentialMovingWindow,
)
from pandas.core.window.rolling import (
Rolling,
Window,
Expand All @@ -42,9 +46,9 @@ import xarray as xr

from pandas._typing import (
S1,
AggFuncType,
AggFuncTypeBase,
AggFuncTypeDict,
AggFuncTypeDictFrame,
AggFuncTypeFrame,
AnyArrayLike,
ArrayLike,
Axes,
Expand All @@ -64,6 +68,7 @@ from pandas._typing import (
IndexingInt,
IndexLabel,
IndexType,
IntervalClosedType,
JsonFrameOrient,
Label,
Level,
Expand All @@ -73,6 +78,7 @@ from pandas._typing import (
MergeHow,
NaPosition,
ParquetEngine,
QuantileInterpolation,
ReadBuffer,
Renamer,
ReplaceMethod,
Expand Down Expand Up @@ -1050,7 +1056,7 @@ class DataFrame(NDFrame, OpsMixin):
@overload
def agg(
self,
func: list[AggFuncTypeBase] | AggFuncTypeDict = ...,
func: list[AggFuncTypeBase] | AggFuncTypeDictFrame = ...,
axis: AxisType = ...,
**kwargs,
) -> DataFrame: ...
Expand All @@ -1061,13 +1067,13 @@ class DataFrame(NDFrame, OpsMixin):
@overload
def aggregate(
self,
func: list[AggFuncTypeBase] | AggFuncTypeDict,
func: list[AggFuncTypeBase] | AggFuncTypeDictFrame,
axis: AxisType = ...,
**kwargs,
) -> DataFrame: ...
def transform(
self,
func: AggFuncType,
func: AggFuncTypeFrame,
axis: AxisType = ...,
*args,
**kwargs,
Expand Down Expand Up @@ -1163,17 +1169,15 @@ class DataFrame(NDFrame, OpsMixin):
q: float = ...,
axis: AxisType = ...,
numeric_only: _bool = ...,
interpolation: _str
| Literal["linear", "lower", "higher", "midpoint", "nearest"] = ...,
interpolation: QuantileInterpolation = ...,
) -> Series: ...
@overload
def quantile(
self,
q: list[float] | np.ndarray,
axis: AxisType = ...,
numeric_only: _bool = ...,
interpolation: _str
| Literal["linear", "lower", "higher", "midpoint", "nearest"] = ...,
interpolation: QuantileInterpolation = ...,
) -> DataFrame: ...
def to_timestamp(
self,
Expand Down Expand Up @@ -1410,8 +1414,13 @@ class DataFrame(NDFrame, OpsMixin):
adjust: _bool = ...,
ignore_na: _bool = ...,
axis: AxisType = ...,
) -> DataFrame: ...
def expanding(self, min_periods: int = ..., axis: AxisType = ...): ... # for now
) -> ExponentialMovingWindow[DataFrame]: ...
def expanding(
self,
min_periods: int = ...,
axis: AxisType = ...,
method: Literal["single", "table"] = ...,
) -> Expanding[DataFrame]: ...
@overload
def ffill(
self,
Expand Down Expand Up @@ -1765,21 +1774,21 @@ class DataFrame(NDFrame, OpsMixin):
center: _bool = ...,
*,
win_type: _str,
on: _str | None = ...,
on: Hashable | None = ...,
axis: AxisType = ...,
closed: _str | None = ...,
) -> Window: ...
closed: IntervalClosedType | None = ...,
) -> Window[DataFrame]: ...
@overload
def rolling(
self,
window,
min_periods: int | None = ...,
center: _bool = ...,
*,
on: _str | None = ...,
on: Hashable | None = ...,
axis: AxisType = ...,
closed: _str | None = ...,
) -> Rolling: ...
closed: IntervalClosedType | None = ...,
) -> Rolling[DataFrame]: ...
def rpow(
self,
other,
Expand Down
6 changes: 3 additions & 3 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ from pandas.core.series import Series

from pandas._typing import (
S1,
AggFuncType,
AggFuncTypeBase,
AggFuncTypeFrame,
AxisType,
Level,
ListLike,
Expand Down Expand Up @@ -154,8 +154,8 @@ class DataFrameGroupBy(GroupBy):
def apply( # pyright: ignore[reportOverlappingOverload]
self, func: Callable[[Iterable], float], *args, **kwargs
) -> DataFrame: ...
def aggregate(self, arg: AggFuncType = ..., *args, **kwargs) -> DataFrame: ...
def agg(self, arg: AggFuncType = ..., *args, **kwargs) -> DataFrame: ...
def aggregate(self, arg: AggFuncTypeFrame = ..., *args, **kwargs) -> DataFrame: ...
agg = aggregate
def transform(self, func, *args, **kwargs): ...
def filter(
self, func: Callable, dropna: bool = ..., *args, **kwargs
Expand Down
50 changes: 21 additions & 29 deletions pandas-stubs/core/series.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ from pandas.core.indexing import (
)
from pandas.core.resample import Resampler
from pandas.core.strings import StringMethods
from pandas.core.window import ExponentialMovingWindow
from pandas.core.window import (
Expanding,
ExponentialMovingWindow,
Rolling,
)
from pandas.core.window.rolling import (
Rolling,
Window,
Expand All @@ -59,7 +63,8 @@ import xarray as xr
from pandas._typing import (
S1,
AggFuncTypeBase,
AggFuncTypeDict,
AggFuncTypeDictFrame,
AggFuncTypeSeriesToFrame,
ArrayLike,
Axes,
Axis,
Expand All @@ -79,6 +84,7 @@ from pandas._typing import (
MaskType,
MergeHow,
NaPosition,
QuantileInterpolation,
Renamer,
ReplaceMethod,
Scalar,
Expand Down Expand Up @@ -453,15 +459,13 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
def quantile(
self,
q: float = ...,
interpolation: _str
| Literal["linear", "lower", "higher", "midpoint", "nearest"] = ...,
interpolation: QuantileInterpolation = ...,
) -> float: ...
@overload
def quantile(
self,
q: _ListLike,
interpolation: _str
| Literal["linear", "lower", "higher", "midpoint", "nearest"] = ...,
interpolation: QuantileInterpolation = ...,
) -> Series[S1]: ...
def corr(
self,
Expand Down Expand Up @@ -628,27 +632,12 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
@overload
def aggregate(
self,
func: list[AggFuncTypeBase] | dict[Hashable, AggFuncTypeBase] = ...,
axis: SeriesAxisType = ...,
*args,
**kwargs,
) -> Series[S1]: ...
@overload
def agg(
self,
func: AggFuncTypeBase,
axis: SeriesAxisType = ...,
*args,
**kwargs,
) -> S1: ...
@overload
def agg(
self,
func: list[AggFuncTypeBase] | dict[Hashable, AggFuncTypeBase] = ...,
func: AggFuncTypeSeriesToFrame = ...,
axis: SeriesAxisType = ...,
*args,
**kwargs,
) -> Series[S1]: ...
agg = aggregate
@overload
def transform(
self,
Expand All @@ -660,7 +649,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
@overload
def transform(
self,
func: list[AggFuncTypeBase] | AggFuncTypeDict,
func: list[AggFuncTypeBase] | AggFuncTypeDictFrame,
axis: SeriesAxisType = ...,
*args,
**kwargs,
Expand Down Expand Up @@ -1321,10 +1310,13 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
adjust: _bool = ...,
ignore_na: _bool = ...,
axis: SeriesAxisType = ...,
) -> ExponentialMovingWindow: ...
) -> ExponentialMovingWindow[Series]: ...
def expanding(
self, min_periods: int = ..., axis: SeriesAxisType = ...
) -> DataFrame: ...
self,
min_periods: int = ...,
axis: SeriesAxisType = ...,
method: Literal["single", "table"] = ...,
) -> Expanding[Series]: ...
def floordiv(
self,
other: num | _ListLike | Series[S1],
Expand Down Expand Up @@ -1527,7 +1519,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
on: _str | None = ...,
axis: SeriesAxisType = ...,
closed: _str | None = ...,
) -> Window: ...
) -> Window[Series]: ...
@overload
def rolling(
self,
Expand All @@ -1538,7 +1530,7 @@ class Series(IndexOpsMixin, NDFrame, Generic[S1]):
on: _str | None = ...,
axis: SeriesAxisType = ...,
closed: _str | None = ...,
) -> Rolling: ...
) -> Rolling[Series]: ...
def rpow(
self,
other: Series[S1] | Scalar,
Expand Down
Loading