From 3542aae009bca92388dfc7000a1caf410c1da196 Mon Sep 17 00:00:00 2001 From: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com> Date: Sun, 4 Aug 2024 17:07:39 +0000 Subject: [PATCH 1/6] Fix pandas.api.extensions.ExtensionArray._pad_or_backfill Add 'limit_area' parameter, return value description and 'See Also' section --- ci/code_checks.sh | 1 - pandas/core/arrays/base.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index e9f4ee1f391a2..25b2dbf89b644 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -193,7 +193,6 @@ 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._pad_or_backfill PR01,RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray._reduce RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray._values_for_factorize SA01" \ -i "pandas.api.extensions.ExtensionArray.astype SA01" \ diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index a0c318409d6bb..408e49721cdff 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1032,6 +1032,12 @@ def _pad_or_backfill( maximum number of entries along the entire axis where NaNs will be filled. + limit_area : {'inside', 'outside'} or None, default None + Specifies which area to limit filling. + - 'inside': Limit the filling to the area within the gaps. + - 'outside': Limit the filling to the area outside the gaps. + If `None`, no limitation is applied. + copy : bool, default True Whether to make a copy of the data before filling. If False, then the original should be modified and no new memory should be allocated. @@ -1043,6 +1049,16 @@ def _pad_or_backfill( Returns ------- Same type as self + The filled array with the same type as the original. + + See Also + -------- + Series.ffill : Forward fill missing values. + Series.bfill : Backward fill missing values. + DataFrame.ffill : Forward fill missing values in DataFrame. + DataFrame.bfill : Backward fill missing values in DataFrame. + api.types.isna : Check for missing values. + api.types.isnull : Check for missing values. Examples -------- From e956c1778da14b9b85dbce695487d58113ca70bb Mon Sep 17 00:00:00 2001 From: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com> Date: Sun, 4 Aug 2024 17:31:37 +0000 Subject: [PATCH 2/6] Fix pandas.api.extensions.ExtensionArray._reduce Add return value description and 'See Also' section --- ci/code_checks.sh | 1 - pandas/core/arrays/base.py | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 25b2dbf89b644..2f641a33f2b1c 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -193,7 +193,6 @@ 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._reduce RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray._values_for_factorize SA01" \ -i "pandas.api.extensions.ExtensionArray.astype SA01" \ -i "pandas.api.extensions.ExtensionArray.dropna RT03,SA01" \ diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 408e49721cdff..f53db47c02158 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -2004,16 +2004,47 @@ def _reduce( Returns ------- - scalar + scalar or ndarray: + The result of the reduction operation. The type of the result + depends on `keepdims`: + - If `keepdims` is `False`, a scalar value is returned. + - If `keepdims` is `True`, the result is wrapped in a numpy array with + a single element. Raises ------ TypeError : subclass does not define operations + See Also + -------- + Series.min : Return the minimum value. + Series.max : Return the maximum value. + Series.sum : Return the sum of values. + Series.mean : Return the mean of values. + Series.median : Return the median of values. + Series.std : Return the standard deviation. + Series.var : Return the variance. + Series.prod : Return the product of values. + Series.sem : Return the standard error of the mean. + Series.kurt : Return the kurtosis. + Series.skew : Return the skewness. + Examples -------- >>> pd.array([1, 2, 3])._reduce("min") 1 + >>> pd.array([1, 2, 3])._reduce("max") + 3 + >>> pd.array([1, 2, 3])._reduce("sum") + 6 + >>> pd.array([1, 2, 3])._reduce("mean") + 2.0 + >>> pd.array([1, 2, 3])._reduce("median") + 2.0 + >>> pd.array([1, np.nan, 2, np.nan])._reduce("sum", skipna=False) + nan + >>> pd.array([1, np.nan, 2, np.nan])._reduce("sum", skipna=True) + 3 """ meth = getattr(self, name, None) if meth is None: From 08636dbc028527a4e71a1fc4d9e9fe914c89dcc7 Mon Sep 17 00:00:00 2001 From: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com> Date: Sun, 4 Aug 2024 17:37:31 +0000 Subject: [PATCH 3/6] Fix pandas.api.extensions.ExtensionArray._values_for_factorize Add 'See Also' section --- ci/code_checks.sh | 1 - pandas/core/arrays/base.py | 4 ++++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 2f641a33f2b1c..40fe60a01d2c4 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -193,7 +193,6 @@ 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._values_for_factorize SA01" \ -i "pandas.api.extensions.ExtensionArray.astype SA01" \ -i "pandas.api.extensions.ExtensionArray.dropna RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray.dtype SA01" \ diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index f53db47c02158..425d5dcbb01fb 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1439,6 +1439,10 @@ def _values_for_factorize(self) -> tuple[np.ndarray, Any]: `-1` and not included in `uniques`. By default, ``np.nan`` is used. + See Also + -------- + util.hash_pandas_object : Hash the pandas object. + Notes ----- The values returned by this method are also used in From e1e09eb2bf07e00166e2bfd37de2b7a3aef68f93 Mon Sep 17 00:00:00 2001 From: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com> Date: Sun, 4 Aug 2024 17:47:54 +0000 Subject: [PATCH 4/6] Fix pandas.api.extensions.ExtensionArray.astype Add 'See Also' section --- ci/code_checks.sh | 1 - pandas/core/arrays/base.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 40fe60a01d2c4..77018c4709477 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -193,7 +193,6 @@ 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.astype SA01" \ -i "pandas.api.extensions.ExtensionArray.dropna RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray.dtype SA01" \ -i "pandas.api.extensions.ExtensionArray.duplicated RT03,SA01" \ diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 425d5dcbb01fb..a9a7ce9f83728 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -713,6 +713,16 @@ def astype(self, dtype: AstypeArg, copy: bool = True) -> ArrayLike: An ``ExtensionArray`` if ``dtype`` is ``ExtensionDtype``, otherwise a Numpy ndarray with ``dtype`` for its dtype. + See Also + -------- + Series.astype : Cast a Series to a different dtype. + DataFrame.astype : Cast a DataFrame to a different dtype. + api.extensions.ExtensionArray : Base class for ExtensionArray objects. + core.arrays.DatetimeArray._from_sequence : Create a DatetimeArray from a + sequence. + core.arrays.TimedeltaArray._from_sequence : Create a TimedeltaArray from + a sequence. + Examples -------- >>> arr = pd.array([1, 2, 3]) From 3ac2a29988126c9fa4b242de41bfa988aabac048 Mon Sep 17 00:00:00 2001 From: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com> Date: Sun, 4 Aug 2024 17:56:15 +0000 Subject: [PATCH 5/6] Fix pandas.api.extensions.ExtensionArray.dropna Add return value description and 'See Also' section --- ci/code_checks.sh | 1 - pandas/core/arrays/base.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 77018c4709477..ec4e1ecab85a6 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -193,7 +193,6 @@ 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.dropna RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray.dtype SA01" \ -i "pandas.api.extensions.ExtensionArray.duplicated RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray.fillna SA01" \ diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index a9a7ce9f83728..7da3b46e47961 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -1175,6 +1175,16 @@ def dropna(self) -> Self: Returns ------- + Self + An ExtensionArray of the same type as the original but with all + NA values removed. + + See Also + -------- + Series.dropna : Remove missing values from a Series. + DataFrame.dropna : Remove missing values from a DataFrame. + api.extensions.ExtensionArray.isna : Check for missing values in + an ExtensionArray. Examples -------- From 02487c7be90cfe83ac9f2c5eafcc39cc3d1bf389 Mon Sep 17 00:00:00 2001 From: ivonastojanovic <80911834+ivonastojanovic@users.noreply.github.com> Date: Sun, 4 Aug 2024 18:08:36 +0000 Subject: [PATCH 6/6] Fix pandas.api.extensions.ExtensionArray.dtype Add 'See Also' section --- ci/code_checks.sh | 1 - pandas/core/arrays/base.py | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index ec4e1ecab85a6..8c8ab1c5f383c 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -193,7 +193,6 @@ 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.dtype SA01" \ -i "pandas.api.extensions.ExtensionArray.duplicated RT03,SA01" \ -i "pandas.api.extensions.ExtensionArray.fillna SA01" \ -i "pandas.api.extensions.ExtensionArray.insert PR07,RT03,SA01" \ diff --git a/pandas/core/arrays/base.py b/pandas/core/arrays/base.py index 7da3b46e47961..f05d1ae18c604 100644 --- a/pandas/core/arrays/base.py +++ b/pandas/core/arrays/base.py @@ -608,6 +608,14 @@ def dtype(self) -> ExtensionDtype: """ An instance of ExtensionDtype. + See Also + -------- + api.extensions.ExtensionDtype : Base class for extension dtypes. + api.extensions.ExtensionArray : Base class for extension array types. + api.extensions.ExtensionArray.dtype : The dtype of an ExtensionArray. + Series.dtype : The dtype of a Series. + DataFrame.dtype : The dtype of a DataFrame. + Examples -------- >>> pd.array([1, 2, 3]).dtype @@ -2065,10 +2073,6 @@ def _reduce( 2.0 >>> pd.array([1, 2, 3])._reduce("median") 2.0 - >>> pd.array([1, np.nan, 2, np.nan])._reduce("sum", skipna=False) - nan - >>> pd.array([1, np.nan, 2, np.nan])._reduce("sum", skipna=True) - 3 """ meth = getattr(self, name, None) if meth is None: