From 74145e5318cdc4ebf3a4015bb210f34563d5bb97 Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 15 Mar 2023 15:50:07 -0700 Subject: [PATCH 1/2] TYP/CLN: remove no-longer-needed overrides --- pandas/core/frame.py | 242 ++----------------------------------- pandas/core/generic.py | 2 +- pandas/core/series.py | 267 +---------------------------------------- 3 files changed, 11 insertions(+), 500 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 19e3eed2d3444..1a930fe68d33b 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -6792,14 +6792,13 @@ def sort_values( elif len(by): # len(by) == 1 - by = by[0] - k = self._get_label_or_level_values(by, axis=axis) + k = self._get_label_or_level_values(by[0], axis=axis) # need to rewrap column in Series to apply key function if key is not None: # error: Incompatible types in assignment (expression has type # "Series", variable has type "ndarray") - k = Series(k, name=by) # type: ignore[assignment] + k = Series(k, name=by[0]) # type: ignore[assignment] if isinstance(ascending, (tuple, list)): ascending = ascending[0] @@ -11386,8 +11385,7 @@ def quantile( keys = [data._get_label_or_level_values(x) for x in by] indexer = lexsort_indexer(keys) else: - by = by[0] - k = data._get_label_or_level_values(by) # type: ignore[arg-type] + k = data._get_label_or_level_values(by[0]) indexer = nargsort(k) res = data._mgr.take(indexer[q_idx], verify=False) @@ -11667,10 +11665,12 @@ def isin(self, values: Series | DataFrame | Sequence | Mapping) -> DataFrame: # error: Argument 2 to "isin" has incompatible type "Union[Sequence[Any], # Mapping[Any, Any]]"; expected "Union[Union[ExtensionArray, # ndarray[Any, Any]], Index, Series]" + res_values = algorithms.isin( + self.values.ravel(), + values, # type: ignore[arg-type] + ) result = self._constructor( - algorithms.isin( - self.values.ravel(), values # type: ignore[arg-type] - ).reshape(self.shape), + res_values.reshape(self.shape), self.index, self.columns, ) @@ -11795,232 +11795,6 @@ def values(self) -> np.ndarray: """ return self._mgr.as_array() - @overload - def ffill( - self, - *, - axis: None | Axis = ..., - inplace: Literal[False] = ..., - limit: None | int = ..., - downcast: dict | None = ..., - ) -> DataFrame: - ... - - @overload - def ffill( - self, - *, - axis: None | Axis = ..., - inplace: Literal[True], - limit: None | int = ..., - downcast: dict | None = ..., - ) -> None: - ... - - @overload - def ffill( - self, - *, - axis: None | Axis = ..., - inplace: bool = ..., - limit: None | int = ..., - downcast: dict | None = ..., - ) -> DataFrame | None: - ... - - def ffill( - self, - *, - axis: None | Axis = None, - inplace: bool = False, - limit: None | int = None, - downcast: dict | None = None, - ) -> DataFrame | None: - return super().ffill(axis=axis, inplace=inplace, limit=limit, downcast=downcast) - - @overload - def bfill( - self, - *, - axis: None | Axis = ..., - inplace: Literal[False] = ..., - limit: None | int = ..., - downcast=..., - ) -> DataFrame: - ... - - @overload - def bfill( - self, - *, - axis: None | Axis = ..., - inplace: Literal[True], - limit: None | int = ..., - downcast=..., - ) -> None: - ... - - @overload - def bfill( - self, - *, - axis: None | Axis = ..., - inplace: bool = ..., - limit: None | int = ..., - downcast=..., - ) -> DataFrame | None: - ... - - def bfill( - self, - *, - axis: None | Axis = None, - inplace: bool = False, - limit: None | int = None, - downcast=None, - ) -> DataFrame | None: - return super().bfill(axis=axis, inplace=inplace, limit=limit, downcast=downcast) - - def clip( - self: DataFrame, - lower: float | None = None, - upper: float | None = None, - *, - axis: Axis | None = None, - inplace: bool = False, - **kwargs, - ) -> DataFrame | None: - return super().clip(lower, upper, axis=axis, inplace=inplace, **kwargs) - - def interpolate( - self: DataFrame, - method: str = "linear", - *, - axis: Axis = 0, - limit: int | None = None, - inplace: bool = False, - limit_direction: str | None = None, - limit_area: str | None = None, - downcast: str | None = None, - **kwargs, - ) -> DataFrame | None: - return super().interpolate( - method=method, - axis=axis, - limit=limit, - inplace=inplace, - limit_direction=limit_direction, - limit_area=limit_area, - downcast=downcast, - **kwargs, - ) - - @overload - def where( - self, - cond, - other=..., - *, - inplace: Literal[False] = ..., - axis: Axis | None = ..., - level: Level = ..., - ) -> DataFrame: - ... - - @overload - def where( - self, - cond, - other=..., - *, - inplace: Literal[True], - axis: Axis | None = ..., - level: Level = ..., - ) -> None: - ... - - @overload - def where( - self, - cond, - other=..., - *, - inplace: bool = ..., - axis: Axis | None = ..., - level: Level = ..., - ) -> DataFrame | None: - ... - - def where( - self, - cond, - other=lib.no_default, - *, - inplace: bool = False, - axis: Axis | None = None, - level: Level = None, - ) -> DataFrame | None: - return super().where( - cond, - other, - inplace=inplace, - axis=axis, - level=level, - ) - - @overload - def mask( - self, - cond, - other=..., - *, - inplace: Literal[False] = ..., - axis: Axis | None = ..., - level: Level = ..., - ) -> DataFrame: - ... - - @overload - def mask( - self, - cond, - other=..., - *, - inplace: Literal[True], - axis: Axis | None = ..., - level: Level = ..., - ) -> None: - ... - - @overload - def mask( - self, - cond, - other=..., - *, - inplace: bool = ..., - axis: Axis | None = ..., - level: Level = ..., - ) -> DataFrame | None: - ... - - def mask( - self, - cond, - other=lib.no_default, - *, - inplace: bool = False, - axis: Axis | None = None, - level: Level = None, - ) -> DataFrame | None: - return super().mask( - cond, - other, - inplace=inplace, - axis=axis, - level=level, - ) - DataFrame._add_numeric_operations() diff --git a/pandas/core/generic.py b/pandas/core/generic.py index c3818a0a425b9..a3bd8f147eca1 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -11994,7 +11994,7 @@ def ewm( # Arithmetic Methods @final - def _inplace_method(self, other, op): + def _inplace_method(self, other, op) -> Self: """ Wrap arithmetic method to operate inplace. """ diff --git a/pandas/core/series.py b/pandas/core/series.py index 7050dd0ffb7df..6fb2bf1d384a4 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -4349,43 +4349,6 @@ def aggregate(self, func=None, axis: Axis = 0, *args, **kwargs): agg = aggregate - # error: Signature of "any" incompatible with supertype "NDFrame" [override] - @overload # type: ignore[override] - def any( - self, - *, - axis: Axis = ..., - bool_only: bool | None = ..., - skipna: bool = ..., - level: None = ..., - **kwargs, - ) -> bool: - ... - - @overload - def any( - self, - *, - axis: Axis = ..., - bool_only: bool | None = ..., - skipna: bool = ..., - level: Level, - **kwargs, - ) -> Series | bool: - ... - - # error: Missing return statement - @doc(NDFrame.any, **_shared_doc_kwargs) - def any( # type: ignore[empty-body] - self, - axis: Axis = 0, - bool_only: bool | None = None, - skipna: bool = True, - level: Level | None = None, - **kwargs, - ) -> Series | bool: - ... - @doc( _shared_docs["transform"], klass=_shared_doc_kwargs["klass"], @@ -4811,14 +4774,14 @@ def reindex( # type: ignore[override] @doc(NDFrame.rename_axis) def rename_axis( # type: ignore[override] - self: Series, + self, mapper: IndexLabel | lib.NoDefault = lib.no_default, *, index=lib.no_default, axis: Axis = 0, copy: bool = True, inplace: bool = False, - ) -> Series | None: + ) -> Self | None: return super().rename_axis( mapper=mapper, index=index, @@ -5714,232 +5677,6 @@ def to_period(self, freq: str | None = None, copy: bool | None = None) -> Series setattr(new_obj, "index", new_index) return new_obj - @overload - def ffill( - self, - *, - axis: None | Axis = ..., - inplace: Literal[False] = ..., - limit: None | int = ..., - downcast: dict | None = ..., - ) -> Series: - ... - - @overload - def ffill( - self, - *, - axis: None | Axis = ..., - inplace: Literal[True], - limit: None | int = ..., - downcast: dict | None = ..., - ) -> None: - ... - - @overload - def ffill( - self, - *, - axis: None | Axis = ..., - inplace: bool = ..., - limit: None | int = ..., - downcast: dict | None = ..., - ) -> Series | None: - ... - - def ffill( - self, - *, - axis: None | Axis = None, - inplace: bool = False, - limit: None | int = None, - downcast: dict | None = None, - ) -> Series | None: - return super().ffill(axis=axis, inplace=inplace, limit=limit, downcast=downcast) - - @overload - def bfill( - self, - *, - axis: None | Axis = ..., - inplace: Literal[False] = ..., - limit: None | int = ..., - downcast: dict | None = ..., - ) -> Series: - ... - - @overload - def bfill( - self, - *, - axis: None | Axis = ..., - inplace: Literal[True], - limit: None | int = ..., - downcast: dict | None = ..., - ) -> None: - ... - - @overload - def bfill( - self, - *, - axis: None | Axis = ..., - inplace: bool = ..., - limit: None | int = ..., - downcast: dict | None = ..., - ) -> Series | None: - ... - - def bfill( - self, - *, - axis: None | Axis = None, - inplace: bool = False, - limit: None | int = None, - downcast: dict | None = None, - ) -> Series | None: - return super().bfill(axis=axis, inplace=inplace, limit=limit, downcast=downcast) - - def clip( - self: Series, - lower=None, - upper=None, - *, - axis: Axis | None = None, - inplace: bool = False, - **kwargs, - ) -> Series | None: - return super().clip(lower, upper, axis=axis, inplace=inplace, **kwargs) - - def interpolate( - self: Series, - method: str = "linear", - *, - axis: Axis = 0, - limit: int | None = None, - inplace: bool = False, - limit_direction: str | None = None, - limit_area: str | None = None, - downcast: str | None = None, - **kwargs, - ) -> Series | None: - return super().interpolate( - method=method, - axis=axis, - limit=limit, - inplace=inplace, - limit_direction=limit_direction, - limit_area=limit_area, - downcast=downcast, - **kwargs, - ) - - @overload - def where( - self, - cond, - other=..., - *, - inplace: Literal[False] = ..., - axis: Axis | None = ..., - level: Level = ..., - ) -> Series: - ... - - @overload - def where( - self, - cond, - other=..., - *, - inplace: Literal[True], - axis: Axis | None = ..., - level: Level = ..., - ) -> None: - ... - - @overload - def where( - self, - cond, - other=..., - *, - inplace: bool = ..., - axis: Axis | None = ..., - level: Level = ..., - ) -> Series | None: - ... - - def where( - self, - cond, - other=lib.no_default, - *, - inplace: bool = False, - axis: Axis | None = None, - level: Level = None, - ) -> Series | None: - return super().where( - cond, - other, - inplace=inplace, - axis=axis, - level=level, - ) - - @overload - def mask( - self, - cond, - other=..., - *, - inplace: Literal[False] = ..., - axis: Axis | None = ..., - level: Level = ..., - ) -> Series: - ... - - @overload - def mask( - self, - cond, - other=..., - *, - inplace: Literal[True], - axis: Axis | None = ..., - level: Level = ..., - ) -> None: - ... - - @overload - def mask( - self, - cond, - other=..., - *, - inplace: bool = ..., - axis: Axis | None = ..., - level: Level = ..., - ) -> Series | None: - ... - - def mask( - self, - cond, - other=lib.no_default, - *, - inplace: bool = False, - axis: Axis | None = None, - level: Level = None, - ) -> Series | None: - return super().mask( - cond, - other, - inplace=inplace, - axis=axis, - level=level, - ) - # ---------------------------------------------------------------------- # Add index _AXIS_ORDERS: list[Literal["index", "columns"]] = ["index"] From a121ef52e24d534ca55226e3f876c882962303ab Mon Sep 17 00:00:00 2001 From: Brock Date: Wed, 15 Mar 2023 17:55:09 -0700 Subject: [PATCH 2/2] update code_checks --- ci/code_checks.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 8fefa47c16bab..78f90eb902ea6 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -97,6 +97,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Series.is_monotonic_increasing \ pandas.Series.is_monotonic_decreasing \ pandas.Series.backfill \ + pandas.Series.bfill \ + pandas.Series.ffill \ pandas.Series.pad \ pandas.Series.argsort \ pandas.Series.reorder_levels \ @@ -541,6 +543,8 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.DataFrame.iterrows \ pandas.DataFrame.pipe \ pandas.DataFrame.backfill \ + pandas.DataFrame.bfill \ + pandas.DataFrame.ffill \ pandas.DataFrame.pad \ pandas.DataFrame.swapaxes \ pandas.DataFrame.first_valid_index \