Skip to content

Commit 6852012

Browse files
authored
DOC: Fix examples in documentation (#31472)
1 parent 2a2258d commit 6852012

File tree

4 files changed

+180
-68
lines changed

4 files changed

+180
-68
lines changed

ci/code_checks.sh

+11-5
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,6 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
267267
-k"-nonzero -reindex -searchsorted -to_dict"
268268
RET=$(($RET + $?)) ; echo $MSG "DONE"
269269

270-
MSG='Doctests generic.py' ; echo $MSG
271-
pytest -q --doctest-modules pandas/core/generic.py \
272-
-k"-_set_axis_name -_xs -describe -groupby -interpolate -pct_change -pipe -reindex -reindex_axis -to_json -transpose -values -xs -to_clipboard"
273-
RET=$(($RET + $?)) ; echo $MSG "DONE"
274-
275270
MSG='Doctests groupby.py' ; echo $MSG
276271
pytest -q --doctest-modules pandas/core/groupby/groupby.py -k"-cumcount -describe -pipe"
277272
RET=$(($RET + $?)) ; echo $MSG "DONE"
@@ -311,6 +306,17 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
311306
pytest -q --doctest-modules pandas/core/arrays/boolean.py
312307
RET=$(($RET + $?)) ; echo $MSG "DONE"
313308

309+
MSG='Doctests base.py' ; echo $MSG
310+
pytest -q --doctest-modules pandas/core/base.py
311+
RET=$(($RET + $?)) ; echo $MSG "DONE"
312+
313+
MSG='Doctests construction.py' ; echo $MSG
314+
pytest -q --doctest-modules pandas/core/construction.py
315+
RET=$(($RET + $?)) ; echo $MSG "DONE"
316+
317+
MSG='Doctests generic.py' ; echo $MSG
318+
pytest -q --doctest-modules pandas/core/generic.py
319+
RET=$(($RET + $?)) ; echo $MSG "DONE"
314320
fi
315321

316322
### DOCSTRINGS ###

pandas/core/base.py

+20-12
Original file line numberDiff line numberDiff line change
@@ -1473,41 +1473,49 @@ def factorize(self, sort=False, na_sentinel=-1):
14731473
14741474
Examples
14751475
--------
1476-
>>> x = pd.Series([1, 2, 3])
1477-
>>> x
1476+
>>> ser = pd.Series([1, 2, 3])
1477+
>>> ser
14781478
0 1
14791479
1 2
14801480
2 3
14811481
dtype: int64
14821482
1483-
>>> x.searchsorted(4)
1483+
>>> ser.searchsorted(4)
14841484
3
14851485
1486-
>>> x.searchsorted([0, 4])
1486+
>>> ser.searchsorted([0, 4])
14871487
array([0, 3])
14881488
1489-
>>> x.searchsorted([1, 3], side='left')
1489+
>>> ser.searchsorted([1, 3], side='left')
14901490
array([0, 2])
14911491
1492-
>>> x.searchsorted([1, 3], side='right')
1492+
>>> ser.searchsorted([1, 3], side='right')
14931493
array([1, 3])
14941494
1495-
>>> x = pd.Categorical(['apple', 'bread', 'bread',
1496-
'cheese', 'milk'], ordered=True)
1495+
>>> ser = pd.Categorical(
1496+
... ['apple', 'bread', 'bread', 'cheese', 'milk'], ordered=True
1497+
... )
1498+
>>> ser
14971499
[apple, bread, bread, cheese, milk]
14981500
Categories (4, object): [apple < bread < cheese < milk]
14991501
1500-
>>> x.searchsorted('bread')
1502+
>>> ser.searchsorted('bread')
15011503
1
15021504
1503-
>>> x.searchsorted(['bread'], side='right')
1505+
>>> ser.searchsorted(['bread'], side='right')
15041506
array([3])
15051507
15061508
If the values are not monotonically sorted, wrong locations
15071509
may be returned:
15081510
1509-
>>> x = pd.Series([2, 1, 3])
1510-
>>> x.searchsorted(1)
1511+
>>> ser = pd.Series([2, 1, 3])
1512+
>>> ser
1513+
0 2
1514+
1 1
1515+
2 3
1516+
dtype: int64
1517+
1518+
>>> ser.searchsorted(1) # doctest: +SKIP
15111519
0 # wrong result, correct would be 1
15121520
"""
15131521

pandas/core/construction.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
These should not depend on core.internals.
66
"""
7+
78
from typing import TYPE_CHECKING, Any, Optional, Sequence, Union, cast
89

910
import numpy as np
@@ -200,12 +201,12 @@ def array(
200201
201202
>>> pd.array([1, 2, np.nan])
202203
<IntegerArray>
203-
[1, 2, NaN]
204+
[1, 2, <NA>]
204205
Length: 3, dtype: Int64
205206
206207
>>> pd.array(["a", None, "c"])
207208
<StringArray>
208-
['a', nan, 'c']
209+
['a', <NA>, 'c']
209210
Length: 3, dtype: string
210211
211212
>>> pd.array([pd.Period('2000', freq="D"), pd.Period("2000", freq="D")])

0 commit comments

Comments
 (0)