Skip to content

Commit

Permalink
DOC: Enforce Numpy Docstring Validation | pandas.api.extensions.Exten…
Browse files Browse the repository at this point in the history
…sionArray (#59407)

* Fix pandas.api.extensions.ExtensionArray._pad_or_backfill

Add 'limit_area' parameter, return value description and 'See Also' section

* Fix pandas.api.extensions.ExtensionArray._reduce

Add return value description and 'See Also' section

* Fix pandas.api.extensions.ExtensionArray._values_for_factorize

Add 'See Also' section

* Fix pandas.api.extensions.ExtensionArray.astype

Add 'See Also' section

* Fix pandas.api.extensions.ExtensionArray.dropna

Add return value description and 'See Also' section

* Fix pandas.api.extensions.ExtensionArray.dtype

Add 'See Also' section
  • Loading branch information
ivonastojanovic authored Aug 25, 2024
1 parent 90e8e04 commit 50c3032
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
6 changes: 0 additions & 6 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,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" \
-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" \
-i "pandas.api.extensions.ExtensionArray.insert PR07,RT03,SA01" \
Expand Down
77 changes: 76 additions & 1 deletion pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -713,6 +721,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])
Expand Down Expand Up @@ -1032,6 +1050,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.
Expand All @@ -1043,6 +1067,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
--------
Expand Down Expand Up @@ -1149,6 +1183,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
--------
Expand Down Expand Up @@ -1423,6 +1467,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
Expand Down Expand Up @@ -1988,16 +2036,43 @@ 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
"""
meth = getattr(self, name, None)
if meth is None:
Expand Down

0 comments on commit 50c3032

Please sign in to comment.