From 48ea84845096ab5c027ce4498ef5551bff47711b Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 6 Mar 2021 11:10:22 +0000 Subject: [PATCH] TYP: remove ignores for "Cannot assign to a method" --- pandas/core/generic.py | 58 +++++++++++++----------------------------- 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 140f456926763..ce32124d06f7e 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10596,8 +10596,7 @@ def _add_numeric_operations(cls): def any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): return NDFrame.any(self, axis, bool_only, skipna, level, **kwargs) - # error: Cannot assign to a method - cls.any = any # type: ignore[assignment] + setattr(cls, "any", any) @doc( _bool_doc, @@ -10612,12 +10611,7 @@ def any(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): return NDFrame.all(self, axis, bool_only, skipna, level, **kwargs) - # error: Cannot assign to a method - - # error: Incompatible types in assignment (expression has type - # "Callable[[Iterable[object]], bool]", variable has type "Callable[[NDFrame, - # Any, Any, Any, Any, KwArg(Any)], Any]") - cls.all = all # type: ignore[assignment] + setattr(cls, "all", all) # error: Argument 1 to "doc" has incompatible type "Optional[str]"; expected # "Union[str, Callable[..., Any]]" @@ -10634,8 +10628,7 @@ def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): def mad(self, axis=None, skipna=None, level=None): return NDFrame.mad(self, axis, skipna, level) - # error: Cannot assign to a method - cls.mad = mad # type: ignore[assignment] + setattr(cls, "mad", mad) @doc( _num_ddof_doc, @@ -10657,8 +10650,7 @@ def sem( ): return NDFrame.sem(self, axis, skipna, level, ddof, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.sem = sem # type: ignore[assignment] + setattr(cls, "sem", sem) @doc( _num_ddof_doc, @@ -10679,8 +10671,7 @@ def var( ): return NDFrame.var(self, axis, skipna, level, ddof, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.var = var # type: ignore[assignment] + setattr(cls, "var", var) @doc( _num_ddof_doc, @@ -10702,8 +10693,7 @@ def std( ): return NDFrame.std(self, axis, skipna, level, ddof, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.std = std # type: ignore[assignment] + setattr(cls, "std", std) @doc( _cnum_doc, @@ -10717,8 +10707,7 @@ def std( def cummin(self, axis=None, skipna=True, *args, **kwargs): return NDFrame.cummin(self, axis, skipna, *args, **kwargs) - # error: Cannot assign to a method - cls.cummin = cummin # type: ignore[assignment] + setattr(cls, "cummin", cummin) @doc( _cnum_doc, @@ -10732,8 +10721,7 @@ def cummin(self, axis=None, skipna=True, *args, **kwargs): def cummax(self, axis=None, skipna=True, *args, **kwargs): return NDFrame.cummax(self, axis, skipna, *args, **kwargs) - # error: Cannot assign to a method - cls.cummax = cummax # type: ignore[assignment] + setattr(cls, "cummax", cummax) @doc( _cnum_doc, @@ -10747,8 +10735,7 @@ def cummax(self, axis=None, skipna=True, *args, **kwargs): def cumsum(self, axis=None, skipna=True, *args, **kwargs): return NDFrame.cumsum(self, axis, skipna, *args, **kwargs) - # error: Cannot assign to a method - cls.cumsum = cumsum # type: ignore[assignment] + setattr(cls, "cumsum", cumsum) @doc( _cnum_doc, @@ -10762,8 +10749,7 @@ def cumsum(self, axis=None, skipna=True, *args, **kwargs): def cumprod(self, axis=None, skipna=True, *args, **kwargs): return NDFrame.cumprod(self, axis, skipna, *args, **kwargs) - # error: Cannot assign to a method - cls.cumprod = cumprod # type: ignore[assignment] + setattr(cls, "cumprod", cumprod) @doc( _num_doc, @@ -10789,8 +10775,7 @@ def sum( self, axis, skipna, level, numeric_only, min_count, **kwargs ) - # error: Cannot assign to a method - cls.sum = sum # type: ignore[assignment] + setattr(cls, "sum", sum) @doc( _num_doc, @@ -10815,8 +10800,7 @@ def prod( self, axis, skipna, level, numeric_only, min_count, **kwargs ) - # error: Cannot assign to a method - cls.prod = prod # type: ignore[assignment] + setattr(cls, "prod", prod) cls.product = prod @doc( @@ -10832,8 +10816,7 @@ def prod( def mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.mean(self, axis, skipna, level, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.mean = mean # type: ignore[assignment] + setattr(cls, "mean", mean) @doc( _num_doc, @@ -10848,8 +10831,7 @@ def mean(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): def skew(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.skew(self, axis, skipna, level, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.skew = skew # type: ignore[assignment] + setattr(cls, "skew", skew) @doc( _num_doc, @@ -10867,8 +10849,7 @@ def skew(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): def kurt(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.kurt(self, axis, skipna, level, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.kurt = kurt # type: ignore[assignment] + setattr(cls, "kurt", kurt) cls.kurtosis = kurt @doc( @@ -10886,8 +10867,7 @@ def median( ): return NDFrame.median(self, axis, skipna, level, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.median = median # type: ignore[assignment] + setattr(cls, "median", median) @doc( _num_doc, @@ -10904,8 +10884,7 @@ def median( def max(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.max(self, axis, skipna, level, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.max = max # type: ignore[assignment] + setattr(cls, "max", max) @doc( _num_doc, @@ -10922,8 +10901,7 @@ def max(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): def min(self, axis=None, skipna=None, level=None, numeric_only=None, **kwargs): return NDFrame.min(self, axis, skipna, level, numeric_only, **kwargs) - # error: Cannot assign to a method - cls.min = min # type: ignore[assignment] + setattr(cls, "min", min) @final @doc(Rolling)