Skip to content

Rework groupby and resample core modules #848

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 23 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
59 changes: 54 additions & 5 deletions pandas-stubs/core/groupby/generic.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ from pandas._typing import (
WindowingEngineKwargs,
)

from pandas.plotting import boxplot_frame_groupby

AggScalar: TypeAlias = str | Callable[..., Any]

class NamedAgg(NamedTuple):
Expand Down Expand Up @@ -180,7 +178,9 @@ class SeriesGroupBy(GroupBy[Series[S1]], Generic[S1, ByT]):
def unique(self) -> Series: ...
# Overrides that provide more precise return types over the GroupBy class
@final # type: ignore[misc]
def __iter__(self) -> Iterator[tuple[ByT, Series[S1]]]: ... # pyright: ignore
def __iter__( # pyright: ignore[reportIncompatibleMethodOverride]
self,
) -> Iterator[tuple[ByT, Series[S1]]]: ...

class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT]):
# error: Overload 3 for "apply" will never be used because its parameters overlap overload 1
Expand Down Expand Up @@ -250,7 +250,54 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT]):
skipna: bool = ...,
numeric_only: bool = ...,
) -> DataFrame: ...
boxplot = boxplot_frame_groupby
@overload
def boxplot(
grouped,
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(
grouped,
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(
grouped,
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,
Expand Down Expand Up @@ -349,4 +396,6 @@ class DataFrameGroupBy(GroupBy[DataFrame], Generic[ByT]):
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__(self) -> Iterator[tuple[ByT, DataFrame]]: ... # pyright: ignore
def __iter__( # pyright: ignore[reportIncompatibleMethodOverride]
self,
) -> Iterator[tuple[ByT, DataFrame]]: ...
9 changes: 0 additions & 9 deletions pandas-stubs/core/groupby/grouper.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ class Grouper:
) -> Self: ...
@overload
def __new__(cls, *args, freq: Frequency, **kwargs) -> TimeGrouper: ...
def __init__(
self,
key: KeysArgType | None = ...,
level: Level | ListLikeHashable[Level] | None = ...,
freq: Frequency | None = ...,
axis: Axis | NoDefault = ...,
sort: bool = ...,
dropna: bool = ...,
) -> None: ...
@final
def __repr__(self) -> str: ... # noqa: PYI029 __repr__ here is final

Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/groupby/ops.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class BinGrouper(BaseGrouper):
binlabels: Index
indexer: npt.NDArray[np.intp]
@cache_readonly
def indices(self) -> dict[Incomplete, list[int]]: ... # type: ignore[override] # pyright: ignore
def indices(self) -> dict[Incomplete, list[int]]: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

class DataSplitter(Generic[NDFrameT]):
data: NDFrameT
Expand Down
2 changes: 1 addition & 1 deletion pandas-stubs/core/resample.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Resampler(BaseGroupBy[NDFrameT]):
# We lie about inheriting from Resampler because at runtime inherits all Resampler
# attributes via setattr
class _GroupByMixin(Resampler[NDFrameT]):
k: str | list[str] | None
key: str | list[str] | None
def __getitem__(self, key) -> Self: ... # type: ignore[override] # pyright: ignore[reportIncompatibleMethodOverride]

class DatetimeIndexResampler(Resampler[NDFrameT]): ...
Expand Down
10 changes: 0 additions & 10 deletions pandas-stubs/core/window/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,3 @@ from pandas.core.window.rolling import (
RollingGroupby as RollingGroupby,
Window as Window,
)

__all__ = [
"Expanding",
"ExpandingGroupby",
"ExponentialMovingWindow",
"ExponentialMovingWindowGroupby",
"Rolling",
"RollingGroupby",
"Window",
]
1 change: 0 additions & 1 deletion pandas-stubs/plotting/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pandas.plotting._core import (
PlotAccessor as PlotAccessor,
boxplot as boxplot,
boxplot_frame_groupby as boxplot_frame_groupby,
)
from pandas.plotting._misc import (
andrews_curves as andrews_curves,
Expand Down
49 changes: 0 additions & 49 deletions pandas-stubs/plotting/_core.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ from pandas._typing import (
HashableT1,
HashableT2,
HashableT3,
IndexLabel,
npt,
)

Expand Down Expand Up @@ -84,54 +83,6 @@ def boxplot(
return_type: Literal["both"],
**kwargs,
) -> _BoxPlotT: ...
@overload
def boxplot_frame_groupby(
grouped,
subplots: Literal[True] = ...,
column: IndexLabel | None = ...,
fontsize: float | str | None = ...,
rot: float = ...,
grid: bool = ...,
ax: Axes | None = ...,
figsize: tuple[float, float] | None = ...,
layout: tuple[int, int] | None = ...,
sharex: bool = ...,
sharey: bool = ...,
backend: str | None = ...,
**kwargs,
) -> Series: ... # Series[Axes] but this is not allowed
@overload
def boxplot_frame_groupby(
grouped,
subplots: Literal[False],
column: IndexLabel | None = ...,
fontsize: float | str | None = ...,
rot: float = ...,
grid: bool = ...,
ax: Axes | None = ...,
figsize: tuple[float, float] | None = ...,
layout: tuple[int, int] | None = ...,
sharex: bool = ...,
sharey: bool = ...,
backend: str | None = ...,
**kwargs,
) -> Axes: ...
@overload
def boxplot_frame_groupby(
grouped,
subplots: bool,
column: IndexLabel | None = ...,
fontsize: float | str | None = ...,
rot: float = ...,
grid: bool = ...,
ax: Axes | None = ...,
figsize: tuple[float, float] | None = ...,
layout: tuple[int, int] | None = ...,
sharex: bool = ...,
sharey: bool = ...,
backend: str | None = ...,
**kwargs,
) -> Axes | Series: ... # Series[Axes]

class PlotAccessor:
def __init__(self, data) -> None: ...
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mypy = "1.8.0"
pandas = "2.1.4"
pyarrow = ">=10.0.1"
pytest = ">=7.1.2"
pyright = ">=1.1.344"
pyright = ">=1.1.346"
poethepoet = ">=0.16.5"
loguru = ">=0.6.0"
typing-extensions = ">=4.4.0"
Expand Down Expand Up @@ -191,6 +191,7 @@ reportUnknownParameterType = false
reportUnknownVariableType = false
reportUnusedVariable = false
reportPrivateUsage = false
reportSelfClsParameterName = false
# enable optional checks
reportMissingModuleSource = true
useLibraryCodeForTypes = false
Expand Down