Skip to content

Commit 19618ba

Browse files
authored
DOC: Fixing EX01 - Added examples (#54196)
* Examples errors.IntCastingNANError... * Added engine=python
1 parent ab89aef commit 19618ba

File tree

3 files changed

+61
-7
lines changed

3 files changed

+61
-7
lines changed

ci/code_checks.sh

-7
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,9 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
6565
$BASE_DIR/scripts/validate_docstrings.py --format=actions --errors=EX01 --ignore_functions \
6666
pandas.errors.IncompatibilityWarning \
6767
pandas.errors.InvalidComparison \
68-
pandas.errors.IntCastingNaNError \
6968
pandas.errors.LossySetitemError \
70-
pandas.errors.MergeError \
7169
pandas.errors.NoBufferPresent \
72-
pandas.errors.NullFrequencyError \
73-
pandas.errors.NumbaUtilError \
7470
pandas.errors.OptionError \
75-
pandas.errors.OutOfBoundsDatetime \
76-
pandas.errors.OutOfBoundsTimedelta \
77-
pandas.errors.ParserError \
7871
pandas.errors.PerformanceWarning \
7972
pandas.errors.PyperclipException \
8073
pandas.errors.PyperclipWindowsException \

pandas/_libs/tslibs/np_datetime.pyx

+14
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ cdef bint cmp_scalar(int64_t lhs, int64_t rhs, int op) except -1:
158158
class OutOfBoundsDatetime(ValueError):
159159
"""
160160
Raised when the datetime is outside the range that can be represented.
161+
162+
Examples
163+
--------
164+
>>> pd.to_datetime("08335394550")
165+
Traceback (most recent call last):
166+
OutOfBoundsDatetime: Parsing "08335394550" to datetime overflows,
167+
at position 0
161168
"""
162169
pass
163170

@@ -167,6 +174,13 @@ class OutOfBoundsTimedelta(ValueError):
167174
Raised when encountering a timedelta value that cannot be represented.
168175
169176
Representation should be within a timedelta64[ns].
177+
178+
Examples
179+
--------
180+
>>> pd.date_range(start="1/1/1700", freq="B", periods=100000)
181+
Traceback (most recent call last):
182+
OutOfBoundsTimedelta: Cannot cast 139999 days 00:00:00
183+
to unit='ns' without overflow.
170184
"""
171185
# Timedelta analogue to OutOfBoundsDatetime
172186
pass

pandas/errors/__init__.py

+47
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
class IntCastingNaNError(ValueError):
1919
"""
2020
Exception raised when converting (``astype``) an array with NaN to an integer type.
21+
22+
Examples
23+
--------
24+
>>> pd.DataFrame(np.array([[1, np.nan], [2, 3]]), dtype="i8")
25+
Traceback (most recent call last):
26+
IntCastingNaNError: Cannot convert non-finite values (NA or inf) to integer
2127
"""
2228

2329

@@ -27,6 +33,13 @@ class NullFrequencyError(ValueError):
2733
2834
Particularly ``DatetimeIndex.shift``, ``TimedeltaIndex.shift``,
2935
``PeriodIndex.shift``.
36+
37+
Examples
38+
--------
39+
>>> df = pd.DatetimeIndex(["2011-01-01 10:00", "2011-01-01"], freq=None)
40+
>>> df.shift(2)
41+
Traceback (most recent call last):
42+
NullFrequencyError: Cannot shift with no freq
3043
"""
3144

3245

@@ -63,6 +76,17 @@ class ParserError(ValueError):
6376
--------
6477
read_csv : Read CSV (comma-separated) file into a DataFrame.
6578
read_html : Read HTML table into a DataFrame.
79+
80+
Examples
81+
--------
82+
>>> data = '''a,b,c
83+
... cat,foo,bar
84+
... dog,foo,"baz'''
85+
>>> from io import StringIO
86+
>>> pd.read_csv(StringIO(data), skipfooter=1, engine='python')
87+
Traceback (most recent call last):
88+
ParserError: ',' expected after '"'. Error could possibly be due
89+
to parsing errors in the skipped footer rows
6690
"""
6791

6892

@@ -181,6 +205,18 @@ class MergeError(ValueError):
181205
Exception raised when merging data.
182206
183207
Subclass of ``ValueError``.
208+
209+
Examples
210+
--------
211+
>>> left = pd.DataFrame({"a": ["a", "b", "b", "d"],
212+
... "b": ["cat", "dog", "weasel", "horse"]},
213+
... index=range(4))
214+
>>> right = pd.DataFrame({"a": ["a", "b", "c", "d"],
215+
... "c": ["meow", "bark", "chirp", "nay"]},
216+
... index=range(4)).set_index("a")
217+
>>> left.join(right, on="a", validate="one_to_one",)
218+
Traceback (most recent call last):
219+
MergeError: Merge keys are not unique in left dataset; not a one-to-one merge
184220
"""
185221

186222

@@ -225,6 +261,17 @@ def __str__(self) -> str:
225261
class NumbaUtilError(Exception):
226262
"""
227263
Error raised for unsupported Numba engine routines.
264+
265+
Examples
266+
--------
267+
>>> df = pd.DataFrame({"key": ["a", "a", "b", "b"], "data": [1, 2, 3, 4]},
268+
... columns=["key", "data"])
269+
>>> def incorrect_function(x):
270+
... return sum(x) * 2.7
271+
>>> df.groupby("key").agg(incorrect_function, engine="numba")
272+
Traceback (most recent call last):
273+
NumbaUtilError: The first 2 arguments to incorrect_function
274+
must be ['values', 'index']
228275
"""
229276

230277

0 commit comments

Comments
 (0)