From 6fa4eb43fbf01d558c9e8cd0fdde6fa5359c9d19 Mon Sep 17 00:00:00 2001 From: Abhinav Reddy Date: Mon, 26 Aug 2024 12:25:02 -0400 Subject: [PATCH] DOC: Fix Numpy Docstring errors in pandas.api.extensions.ExtensionArray (#59605) * fix duplicated * fix fillna * fix insert * fix isin * fix tolist * fix unique * fix view --------- Co-authored-by: Abhinav Thimma --- ci/code_checks.sh | 7 ----- pandas/core/arrays/base.py | 52 +++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 916720e5a01e3..4ddc429f2a51c 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -173,14 +173,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.tzinfo GL08" \ -i "pandas.Timestamp.value GL08" \ -i "pandas.Timestamp.year GL08" \ - -i "pandas.api.extensions.ExtensionArray.duplicated RT03,SA01" \ - -i "pandas.api.extensions.ExtensionArray.fillna SA01" \ - -i "pandas.api.extensions.ExtensionArray.insert PR07,RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray.interpolate PR01,SA01" \ - -i "pandas.api.extensions.ExtensionArray.isin PR07,RT03,SA01" \ - -i "pandas.api.extensions.ExtensionArray.tolist RT03,SA01" \ - -i "pandas.api.extensions.ExtensionArray.unique RT03,SA01" \ - -i "pandas.api.extensions.ExtensionArray.view SA01" \ -i "pandas.api.interchange.from_dataframe RT03,SA01" \ -i "pandas.api.types.is_bool PR01,SA01" \ -i "pandas.api.types.is_categorical_dtype SA01" \ diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index f05d1ae18c604..2124f86b03b9c 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1137,6 +1137,13 @@ def fillna( ExtensionArray With NA/NaN filled. + See Also + -------- + api.extensions.ExtensionArray.dropna : Return ExtensionArray without + NA values. + api.extensions.ExtensionArray.isna : A 1-D array indicating if + each value is missing. + Examples -------- >>> arr = pd.array([np.nan, np.nan, 2, 3, np.nan, np.nan]) @@ -1220,6 +1227,15 @@ def duplicated( Returns ------- ndarray[bool] + With true in indices where elements are duplicated and false otherwise. + + See Also + -------- + DataFrame.duplicated : Return boolean Series denoting + duplicate rows. + Series.duplicated : Indicate duplicate Series values. + api.extensions.ExtensionArray.unique : Compute the ExtensionArray + of unique values. Examples -------- @@ -1303,6 +1319,13 @@ def unique(self) -> Self: Returns ------- pandas.api.extensions.ExtensionArray + With unique values from the input array. + + See Also + -------- + Index.unique: Return unique values in the index. + Series.unique: Return unique values of Series object. + unique: Return unique values based on a hash table. Examples -------- @@ -1436,10 +1459,18 @@ def isin(self, values: ArrayLike) -> npt.NDArray[np.bool_]: Parameters ---------- values : np.ndarray or ExtensionArray + Values to compare every element in the array against. Returns ------- np.ndarray[bool] + With true at indices where value is in `values`. + + See Also + -------- + DataFrame.isin: Whether each element in the DataFrame is contained in values. + Index.isin: Return a boolean array where the index values are in values. + Series.isin: Whether elements in Series are contained in values. Examples -------- @@ -1743,6 +1774,12 @@ def view(self, dtype: Dtype | None = None) -> ArrayLike: ExtensionArray or np.ndarray A view on the :class:`ExtensionArray`'s data. + See Also + -------- + api.extensions.ExtensionArray.ravel: Return a flattened view on input array. + Index.view: Equivalent function for Index. + ndarray.view: New view of array with the same data. + Examples -------- This gives view on the underlying data of an ``ExtensionArray`` and is not a @@ -2201,6 +2238,12 @@ def tolist(self) -> list: Returns ------- list + Python list of values in array. + + See Also + -------- + Index.to_list: Return a list of the values in the Index. + Series.to_list: Return a list of the values in the Series. Examples -------- @@ -2223,11 +2266,18 @@ def insert(self, loc: int, item) -> Self: Parameters ---------- loc : int + Index where the `item` needs to be inserted. item : scalar-like + Value to be inserted. Returns ------- - same type as self + ExtensionArray + With `item` inserted at `loc`. + + See Also + -------- + Index.insert: Make new Index inserting new item at location. Notes -----