Skip to content

DOC: Fix examples in documentation #31472

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 17 commits into from
Mar 7, 2020
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
16 changes: 11 additions & 5 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,6 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
-k"-nonzero -reindex -searchsorted -to_dict"
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests generic.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/generic.py \
-k"-_set_axis_name -_xs -describe -groupby -interpolate -pct_change -pipe -reindex -reindex_axis -to_json -transpose -values -xs -to_clipboard"
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests groupby.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/groupby/groupby.py -k"-cumcount -describe -pipe"
RET=$(($RET + $?)) ; echo $MSG "DONE"
Expand Down Expand Up @@ -311,6 +306,17 @@ if [[ -z "$CHECK" || "$CHECK" == "doctests" ]]; then
pytest -q --doctest-modules pandas/core/arrays/boolean.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests base.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/base.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests construction.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/construction.py
RET=$(($RET + $?)) ; echo $MSG "DONE"

MSG='Doctests generic.py' ; echo $MSG
pytest -q --doctest-modules pandas/core/generic.py
RET=$(($RET + $?)) ; echo $MSG "DONE"
fi

### DOCSTRINGS ###
Expand Down
32 changes: 20 additions & 12 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,41 +1480,49 @@ def factorize(self, sort=False, na_sentinel=-1):

Examples
--------
>>> x = pd.Series([1, 2, 3])
>>> x
>>> ser = pd.Series([1, 2, 3])
>>> ser
0 1
1 2
2 3
dtype: int64

>>> x.searchsorted(4)
>>> ser.searchsorted(4)
3

>>> x.searchsorted([0, 4])
>>> ser.searchsorted([0, 4])
array([0, 3])

>>> x.searchsorted([1, 3], side='left')
>>> ser.searchsorted([1, 3], side='left')
array([0, 2])

>>> x.searchsorted([1, 3], side='right')
>>> ser.searchsorted([1, 3], side='right')
array([1, 3])

>>> x = pd.Categorical(['apple', 'bread', 'bread',
'cheese', 'milk'], ordered=True)
>>> ser = pd.Categorical(
... ['apple', 'bread', 'bread', 'cheese', 'milk'], ordered=True
... )
>>> ser
[apple, bread, bread, cheese, milk]
Categories (4, object): [apple < bread < cheese < milk]

>>> x.searchsorted('bread')
>>> ser.searchsorted('bread')
1

>>> x.searchsorted(['bread'], side='right')
>>> ser.searchsorted(['bread'], side='right')
array([3])

If the values are not monotonically sorted, wrong locations
may be returned:

>>> x = pd.Series([2, 1, 3])
>>> x.searchsorted(1)
>>> ser = pd.Series([2, 1, 3])
>>> ser
0 2
1 1
2 3
dtype: int64

>>> ser.searchsorted(1) # doctest: +SKIP
0 # wrong result, correct would be 1
"""

Expand Down
5 changes: 3 additions & 2 deletions pandas/core/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

These should not depend on core.internals.
"""

from typing import TYPE_CHECKING, Any, Optional, Sequence, Union, cast

import numpy as np
Expand Down Expand Up @@ -200,12 +201,12 @@ def array(

>>> pd.array([1, 2, np.nan])
<IntegerArray>
[1, 2, NaN]
[1, 2, <NA>]
Length: 3, dtype: Int64

>>> pd.array(["a", None, "c"])
<StringArray>
['a', nan, 'c']
['a', <NA>, 'c']
Length: 3, dtype: string

>>> pd.array([pd.Period('2000', freq="D"), pd.Period("2000", freq="D")])
Expand Down
Loading