Skip to content

DOC: Fixing EX01 - Added examples #54288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then

MSG='Partially validate docstrings (EX01)' ; echo $MSG
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
pandas.errors.PyperclipException \
pandas.errors.PyperclipWindowsException \
pandas.errors.UnsortedIndexError \
pandas.errors.UnsupportedFunctionCall \
pandas.NaT \
pandas.io.stata.StataReader.data_label \
Expand All @@ -77,11 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
pandas.api.extensions.ExtensionDtype \
pandas.api.extensions.ExtensionArray \
pandas.arrays.NumpyExtensionArray \
pandas.api.extensions.ExtensionArray._from_sequence_of_strings \
pandas.api.extensions.ExtensionArray._hash_pandas_object \
pandas.api.extensions.ExtensionArray._reduce \
pandas.api.extensions.ExtensionArray._values_for_factorize \
pandas.api.extensions.ExtensionArray.interpolate \
RET=$(($RET + $?)) ; echo $MSG "DONE"

fi
Expand Down
45 changes: 45 additions & 0 deletions pandas/core/arrays/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,13 @@ def _from_sequence_of_strings(
Returns
-------
ExtensionArray

Examples
--------
>>> pd.arrays.IntegerArray._from_sequence_of_strings(["1", "2", "3"])
<IntegerArray>
[1, 2, 3]
Length: 3, dtype: Int64
"""
raise AbstractMethodError(cls)

Expand Down Expand Up @@ -878,6 +885,22 @@ def interpolate(
) -> Self:
"""
See DataFrame.interpolate.__doc__.

Examples
--------
>>> arr = pd.arrays.NumpyExtensionArray(np.array([0, 1, np.nan, 3]))
>>> arr.interpolate(method="linear",
... limit=3,
... limit_direction="forward",
... index=pd.Index([1, 2, 3, 4]),
... fill_value=1,
... copy=False,
... axis=0,
... limit_area="inside"
... )
<NumpyExtensionArray>
[0.0, 1.0, 2.0, 3.0]
Length: 4, dtype: float64
"""
# NB: we return type(self) even if copy=False
raise NotImplementedError(
Expand Down Expand Up @@ -1212,6 +1235,11 @@ def _values_for_factorize(self) -> tuple[np.ndarray, Any]:
The values returned by this method are also used in
:func:`pandas.util.hash_pandas_object`. If needed, this can be
overridden in the ``self._hash_pandas_object()`` method.

Examples
--------
>>> pd.array([1, 2, 3])._values_for_factorize()
(array([1, 2, 3], dtype=object), nan)
"""
return self.astype(object), np.nan

Expand Down Expand Up @@ -1714,6 +1742,11 @@ def _reduce(
Raises
------
TypeError : subclass does not define reductions

Examples
--------
>>> pd.array([1, 2, 3])._reduce("min")
1
"""
meth = getattr(self, name, None)
if meth is None:
Expand Down Expand Up @@ -1760,12 +1793,24 @@ def _hash_pandas_object(
Parameters
----------
encoding : str
Encoding for data & key when strings.
hash_key : str
Hash_key for string key to encode.
categorize : bool
Whether to first categorize object arrays before hashing. This is more
efficient when the array contains duplicate values.

Returns
-------
np.ndarray[uint64]

Examples
--------
>>> pd.array([1, 2])._hash_pandas_object(encoding='utf-8',
... hash_key="1000000000000000",
... categorize=False
... )
array([11381023671546835630, 4641644667904626417], dtype=uint64)
"""
from pandas.core.util.hashing import hash_array

Expand Down
19 changes: 19 additions & 0 deletions pandas/errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ class UnsortedIndexError(KeyError):
Error raised when slicing a MultiIndex which has not been lexsorted.

Subclass of `KeyError`.

Examples
--------
>>> df = pd.DataFrame({"cat": [0, 0, 1, 1],
... "color": ["white", "white", "brown", "black"],
... "lives": [4, 4, 3, 7]},
... )
>>> df = df.set_index(["cat", "color"])
>>> df
lives
cat color
0 white 4
white 4
1 brown 3
black 7
>>> df.loc[(0, "black"):(1, "white")]
Traceback (most recent call last):
UnsortedIndexError: 'Key length (2) was greater
than MultiIndex lexsort depth (1)'
"""


Expand Down
1 change: 1 addition & 0 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"errors.LossySetitemError",
"errors.NoBufferPresent",
"errors.IncompatibilityWarning",
"errors.PyperclipException",
}
PRIVATE_CLASSES = ["NDFrame", "IndexOpsMixin"]
ERROR_MSGS = {
Expand Down