Skip to content

Commit b66b9e3

Browse files
jbrockmendeltopper-123
authored andcommitted
REF: define reductions non-dynamically (pandas-dev#52428)
1 parent c4cc3c2 commit b66b9e3

File tree

3 files changed

+620
-607
lines changed

3 files changed

+620
-607
lines changed

pandas/core/frame.py

+168-41
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@
140140
sanitize_array,
141141
sanitize_masked_array,
142142
)
143-
from pandas.core.generic import NDFrame
143+
from pandas.core.generic import (
144+
NDFrame,
145+
make_doc,
146+
)
144147
from pandas.core.indexers import check_key_length
145148
from pandas.core.indexes.api import (
146149
DatetimeIndex,
@@ -9592,43 +9595,6 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs):
95929595

95939596
agg = aggregate
95949597

9595-
# error: Signature of "any" incompatible with supertype "NDFrame" [override]
9596-
@overload # type: ignore[override]
9597-
def any(
9598-
self,
9599-
*,
9600-
axis: Axis = ...,
9601-
bool_only: bool | None = ...,
9602-
skipna: bool = ...,
9603-
level: None = ...,
9604-
**kwargs,
9605-
) -> Series:
9606-
...
9607-
9608-
@overload
9609-
def any(
9610-
self,
9611-
*,
9612-
axis: Axis = ...,
9613-
bool_only: bool | None = ...,
9614-
skipna: bool = ...,
9615-
level: Level,
9616-
**kwargs,
9617-
) -> DataFrame | Series:
9618-
...
9619-
9620-
# error: Missing return statement
9621-
@doc(NDFrame.any, **_shared_doc_kwargs)
9622-
def any( # type: ignore[empty-body]
9623-
self,
9624-
axis: Axis = 0,
9625-
bool_only: bool | None = None,
9626-
skipna: bool = True,
9627-
level: Level = None,
9628-
**kwargs,
9629-
) -> DataFrame | Series:
9630-
...
9631-
96329598
@doc(
96339599
_shared_docs["transform"],
96349600
klass=_shared_doc_kwargs["klass"],
@@ -10920,6 +10886,170 @@ def _reduce_axis1(self, name: str, func, skipna: bool) -> Series:
1092010886
res_ser = self._constructor_sliced(result, index=self.index, copy=False)
1092110887
return res_ser
1092210888

10889+
@doc(make_doc("any", ndim=2))
10890+
# error: Signature of "any" incompatible with supertype "NDFrame"
10891+
def any( # type: ignore[override]
10892+
self,
10893+
*,
10894+
axis: Axis = 0,
10895+
bool_only=None,
10896+
skipna: bool = True,
10897+
**kwargs,
10898+
) -> Series:
10899+
# error: Incompatible return value type (got "Union[Series, bool]",
10900+
# expected "Series")
10901+
return self._logical_func( # type: ignore[return-value]
10902+
"any", nanops.nanany, axis, bool_only, skipna, **kwargs
10903+
)
10904+
10905+
@doc(make_doc("all", ndim=2))
10906+
def all(
10907+
self,
10908+
axis: Axis = 0,
10909+
bool_only=None,
10910+
skipna: bool = True,
10911+
**kwargs,
10912+
) -> Series:
10913+
# error: Incompatible return value type (got "Union[Series, bool]",
10914+
# expected "Series")
10915+
return self._logical_func( # type: ignore[return-value]
10916+
"all", nanops.nanall, axis, bool_only, skipna, **kwargs
10917+
)
10918+
10919+
@doc(make_doc("min", ndim=2))
10920+
def min(
10921+
self,
10922+
axis: Axis | None = 0,
10923+
skipna: bool = True,
10924+
numeric_only: bool = False,
10925+
**kwargs,
10926+
):
10927+
return super().min(axis, skipna, numeric_only, **kwargs)
10928+
10929+
@doc(make_doc("max", ndim=2))
10930+
def max(
10931+
self,
10932+
axis: Axis | None = 0,
10933+
skipna: bool = True,
10934+
numeric_only: bool = False,
10935+
**kwargs,
10936+
):
10937+
return super().max(axis, skipna, numeric_only, **kwargs)
10938+
10939+
@doc(make_doc("sum", ndim=2))
10940+
def sum(
10941+
self,
10942+
axis: Axis | None = None,
10943+
skipna: bool = True,
10944+
numeric_only: bool = False,
10945+
min_count: int = 0,
10946+
**kwargs,
10947+
):
10948+
return super().sum(axis, skipna, numeric_only, min_count, **kwargs)
10949+
10950+
@doc(make_doc("prod", ndim=2))
10951+
def prod(
10952+
self,
10953+
axis: Axis | None = None,
10954+
skipna: bool = True,
10955+
numeric_only: bool = False,
10956+
min_count: int = 0,
10957+
**kwargs,
10958+
):
10959+
return super().prod(axis, skipna, numeric_only, min_count, **kwargs)
10960+
10961+
@doc(make_doc("mean", ndim=2))
10962+
def mean(
10963+
self,
10964+
axis: Axis | None = 0,
10965+
skipna: bool = True,
10966+
numeric_only: bool = False,
10967+
**kwargs,
10968+
):
10969+
return super().mean(axis, skipna, numeric_only, **kwargs)
10970+
10971+
@doc(make_doc("median", ndim=2))
10972+
def median(
10973+
self,
10974+
axis: Axis | None = 0,
10975+
skipna: bool = True,
10976+
numeric_only: bool = False,
10977+
**kwargs,
10978+
):
10979+
return super().median(axis, skipna, numeric_only, **kwargs)
10980+
10981+
@doc(make_doc("sem", ndim=2))
10982+
def sem(
10983+
self,
10984+
axis: Axis | None = None,
10985+
skipna: bool = True,
10986+
ddof: int = 1,
10987+
numeric_only: bool = False,
10988+
**kwargs,
10989+
):
10990+
return super().sem(axis, skipna, ddof, numeric_only, **kwargs)
10991+
10992+
@doc(make_doc("var", ndim=2))
10993+
def var(
10994+
self,
10995+
axis: Axis | None = None,
10996+
skipna: bool = True,
10997+
ddof: int = 1,
10998+
numeric_only: bool = False,
10999+
**kwargs,
11000+
):
11001+
return super().var(axis, skipna, ddof, numeric_only, **kwargs)
11002+
11003+
@doc(make_doc("std", ndim=2))
11004+
def std(
11005+
self,
11006+
axis: Axis | None = None,
11007+
skipna: bool = True,
11008+
ddof: int = 1,
11009+
numeric_only: bool = False,
11010+
**kwargs,
11011+
):
11012+
return super().std(axis, skipna, ddof, numeric_only, **kwargs)
11013+
11014+
@doc(make_doc("skew", ndim=2))
11015+
def skew(
11016+
self,
11017+
axis: Axis | None = 0,
11018+
skipna: bool = True,
11019+
numeric_only: bool = False,
11020+
**kwargs,
11021+
):
11022+
return super().skew(axis, skipna, numeric_only, **kwargs)
11023+
11024+
@doc(make_doc("kurt", ndim=2))
11025+
def kurt(
11026+
self,
11027+
axis: Axis | None = 0,
11028+
skipna: bool = True,
11029+
numeric_only: bool = False,
11030+
**kwargs,
11031+
):
11032+
return super().kurt(axis, skipna, numeric_only, **kwargs)
11033+
11034+
kurtosis = kurt
11035+
product = prod
11036+
11037+
@doc(make_doc("cummin", ndim=2))
11038+
def cummin(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
11039+
return NDFrame.cummin(self, axis, skipna, *args, **kwargs)
11040+
11041+
@doc(make_doc("cummax", ndim=2))
11042+
def cummax(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
11043+
return NDFrame.cummax(self, axis, skipna, *args, **kwargs)
11044+
11045+
@doc(make_doc("cumsum", ndim=2))
11046+
def cumsum(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
11047+
return NDFrame.cumsum(self, axis, skipna, *args, **kwargs)
11048+
11049+
@doc(make_doc("cumprod", 2))
11050+
def cumprod(self, axis: Axis | None = None, skipna: bool = True, *args, **kwargs):
11051+
return NDFrame.cumprod(self, axis, skipna, *args, **kwargs)
11052+
1092311053
def nunique(self, axis: Axis = 0, dropna: bool = True) -> Series:
1092411054
"""
1092511055
Count number of distinct elements in specified axis.
@@ -11724,9 +11854,6 @@ def values(self) -> np.ndarray:
1172411854
return self._mgr.as_array()
1172511855

1172611856

11727-
DataFrame._add_numeric_operations()
11728-
11729-
1173011857
def _from_nested_dict(data) -> collections.defaultdict:
1173111858
new_data: collections.defaultdict = collections.defaultdict(dict)
1173211859
for index, s in data.items():

0 commit comments

Comments
 (0)