Skip to content

Commit 12c23c2

Browse files
authored
DOC: Fixing EX01 - Added examples (#54318)
* Examples for UnsupportedFunctionCall ... * Changed ExtensionDtype example, & file's name on StataREader.data_label * removed colon
1 parent 829cf60 commit 12c23c2

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

ci/code_checks.sh

-4
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,12 @@ 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.PyperclipWindowsException \
67-
pandas.errors.UnsupportedFunctionCall \
6866
pandas.NaT \
69-
pandas.io.stata.StataReader.data_label \
7067
pandas.io.stata.StataReader.value_labels \
7168
pandas.io.stata.StataReader.variable_labels \
7269
pandas.io.stata.StataWriter.write_file \
7370
pandas.plotting.deregister_matplotlib_converters \
7471
pandas.plotting.register_matplotlib_converters \
75-
pandas.api.extensions.ExtensionDtype \
7672
pandas.api.extensions.ExtensionArray \
7773
pandas.arrays.NumpyExtensionArray \
7874
RET=$(($RET + $?)) ; echo $MSG "DONE"

pandas/core/dtypes/base.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,22 @@ class property**.
8282
``__eq__`` or ``__hash__``, the default implementations here will not
8383
work.
8484
85+
Examples
86+
--------
87+
8588
For interaction with Apache Arrow (pyarrow), a ``__from_arrow__`` method
8689
can be implemented: this method receives a pyarrow Array or ChunkedArray
8790
as only argument and is expected to return the appropriate pandas
88-
ExtensionArray for this dtype and the passed values::
89-
90-
class ExtensionDtype:
91-
92-
def __from_arrow__(
93-
self, array: Union[pyarrow.Array, pyarrow.ChunkedArray]
94-
) -> ExtensionArray:
95-
...
91+
ExtensionArray for this dtype and the passed values:
92+
93+
>>> import pyarrow
94+
>>> from pandas.api.extensions import ExtensionArray
95+
>>> class ExtensionDtype:
96+
... def __from_arrow__(
97+
... self,
98+
... array: pyarrow.Array | pyarrow.ChunkedArray
99+
... ) -> ExtensionArray:
100+
... ...
96101
97102
This class does not inherit from 'abc.ABCMeta' for performance reasons.
98103
Methods and properties required by the interface raise

pandas/errors/__init__.py

+11
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ class UnsupportedFunctionCall(ValueError):
7474
Exception raised when attempting to call a unsupported numpy function.
7575
7676
For example, ``np.cumsum(groupby_object)``.
77+
78+
Examples
79+
--------
80+
>>> df = pd.DataFrame({"A": [0, 0, 1, 1],
81+
... "B": ["x", "x", "z", "y"],
82+
... "C": [1, 2, 3, 4]}
83+
... )
84+
>>> np.cumsum(df.groupby(["A"]))
85+
Traceback (most recent call last):
86+
UnsupportedFunctionCall: numpy operations are not valid with groupby.
87+
Use .groupby(...).cumsum() instead
7788
"""
7889

7990

pandas/io/stata.py

+13
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,19 @@ def _do_convert_categoricals(
20312031
def data_label(self) -> str:
20322032
"""
20332033
Return data label of Stata file.
2034+
2035+
Examples
2036+
--------
2037+
>>> df = pd.DataFrame([(1,)], columns=["variable"])
2038+
>>> time_stamp = pd.Timestamp(2000, 2, 29, 14, 21)
2039+
>>> data_label = "This is a data file."
2040+
>>> path = "/My_path/filename.dta"
2041+
>>> df.to_stata(path, time_stamp=time_stamp, # doctest: +SKIP
2042+
... data_label=data_label, # doctest: +SKIP
2043+
... version=None) # doctest: +SKIP
2044+
>>> with pd.io.stata.StataReader(path) as reader: # doctest: +SKIP
2045+
... print(reader.data_label) # doctest: +SKIP
2046+
This is a data file.
20342047
"""
20352048
self._ensure_open()
20362049
return self._data_label

scripts/validate_docstrings.py

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"errors.NoBufferPresent",
5555
"errors.IncompatibilityWarning",
5656
"errors.PyperclipException",
57+
"errors.PyperclipWindowsException",
5758
}
5859
PRIVATE_CLASSES = ["NDFrame", "IndexOpsMixin"]
5960
ERROR_MSGS = {

0 commit comments

Comments
 (0)