Skip to content

Commit 075c6c0

Browse files
authored
DOC: Fixing EX01 - Added examples (#54288)
* Examples ExtensionArray._from_sequence_of_strings ... * Moved axis to new line
1 parent a6f5705 commit 075c6c0

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

ci/code_checks.sh

-7
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
6363

6464
MSG='Partially validate docstrings (EX01)' ; echo $MSG
6565
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
66-
pandas.errors.PyperclipException \
6766
pandas.errors.PyperclipWindowsException \
68-
pandas.errors.UnsortedIndexError \
6967
pandas.errors.UnsupportedFunctionCall \
7068
pandas.NaT \
7169
pandas.io.stata.StataReader.data_label \
@@ -77,11 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7775
pandas.api.extensions.ExtensionDtype \
7876
pandas.api.extensions.ExtensionArray \
7977
pandas.arrays.NumpyExtensionArray \
80-
pandas.api.extensions.ExtensionArray._from_sequence_of_strings \
81-
pandas.api.extensions.ExtensionArray._hash_pandas_object \
82-
pandas.api.extensions.ExtensionArray._reduce \
83-
pandas.api.extensions.ExtensionArray._values_for_factorize \
84-
pandas.api.extensions.ExtensionArray.interpolate \
8578
RET=$(($RET + $?)) ; echo $MSG "DONE"
8679

8780
fi

pandas/core/arrays/base.py

+45
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,13 @@ def _from_sequence_of_strings(
301301
Returns
302302
-------
303303
ExtensionArray
304+
305+
Examples
306+
--------
307+
>>> pd.arrays.IntegerArray._from_sequence_of_strings(["1", "2", "3"])
308+
<IntegerArray>
309+
[1, 2, 3]
310+
Length: 3, dtype: Int64
304311
"""
305312
raise AbstractMethodError(cls)
306313

@@ -878,6 +885,22 @@ def interpolate(
878885
) -> Self:
879886
"""
880887
See DataFrame.interpolate.__doc__.
888+
889+
Examples
890+
--------
891+
>>> arr = pd.arrays.NumpyExtensionArray(np.array([0, 1, np.nan, 3]))
892+
>>> arr.interpolate(method="linear",
893+
... limit=3,
894+
... limit_direction="forward",
895+
... index=pd.Index([1, 2, 3, 4]),
896+
... fill_value=1,
897+
... copy=False,
898+
... axis=0,
899+
... limit_area="inside"
900+
... )
901+
<NumpyExtensionArray>
902+
[0.0, 1.0, 2.0, 3.0]
903+
Length: 4, dtype: float64
881904
"""
882905
# NB: we return type(self) even if copy=False
883906
raise NotImplementedError(
@@ -1212,6 +1235,11 @@ def _values_for_factorize(self) -> tuple[np.ndarray, Any]:
12121235
The values returned by this method are also used in
12131236
:func:`pandas.util.hash_pandas_object`. If needed, this can be
12141237
overridden in the ``self._hash_pandas_object()`` method.
1238+
1239+
Examples
1240+
--------
1241+
>>> pd.array([1, 2, 3])._values_for_factorize()
1242+
(array([1, 2, 3], dtype=object), nan)
12151243
"""
12161244
return self.astype(object), np.nan
12171245

@@ -1714,6 +1742,11 @@ def _reduce(
17141742
Raises
17151743
------
17161744
TypeError : subclass does not define reductions
1745+
1746+
Examples
1747+
--------
1748+
>>> pd.array([1, 2, 3])._reduce("min")
1749+
1
17171750
"""
17181751
meth = getattr(self, name, None)
17191752
if meth is None:
@@ -1760,12 +1793,24 @@ def _hash_pandas_object(
17601793
Parameters
17611794
----------
17621795
encoding : str
1796+
Encoding for data & key when strings.
17631797
hash_key : str
1798+
Hash_key for string key to encode.
17641799
categorize : bool
1800+
Whether to first categorize object arrays before hashing. This is more
1801+
efficient when the array contains duplicate values.
17651802
17661803
Returns
17671804
-------
17681805
np.ndarray[uint64]
1806+
1807+
Examples
1808+
--------
1809+
>>> pd.array([1, 2])._hash_pandas_object(encoding='utf-8',
1810+
... hash_key="1000000000000000",
1811+
... categorize=False
1812+
... )
1813+
array([11381023671546835630, 4641644667904626417], dtype=uint64)
17691814
"""
17701815
from pandas.core.util.hashing import hash_array
17711816

pandas/errors/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ class UnsortedIndexError(KeyError):
8282
Error raised when slicing a MultiIndex which has not been lexsorted.
8383
8484
Subclass of `KeyError`.
85+
86+
Examples
87+
--------
88+
>>> df = pd.DataFrame({"cat": [0, 0, 1, 1],
89+
... "color": ["white", "white", "brown", "black"],
90+
... "lives": [4, 4, 3, 7]},
91+
... )
92+
>>> df = df.set_index(["cat", "color"])
93+
>>> df
94+
lives
95+
cat color
96+
0 white 4
97+
white 4
98+
1 brown 3
99+
black 7
100+
>>> df.loc[(0, "black"):(1, "white")]
101+
Traceback (most recent call last):
102+
UnsortedIndexError: 'Key length (2) was greater
103+
than MultiIndex lexsort depth (1)'
85104
"""
86105

87106

scripts/validate_docstrings.py

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"errors.LossySetitemError",
5454
"errors.NoBufferPresent",
5555
"errors.IncompatibilityWarning",
56+
"errors.PyperclipException",
5657
}
5758
PRIVATE_CLASSES = ["NDFrame", "IndexOpsMixin"]
5859
ERROR_MSGS = {

0 commit comments

Comments
 (0)