Skip to content

DOC: correct Series.searchsorted example #19784

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 3 commits into from
Feb 21, 2018
Merged
Changes from 2 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
23 changes: 9 additions & 14 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,32 +1154,27 @@ def factorize(self, sort=False, na_sentinel=-1):
dtype: int64

>>> x.searchsorted(4)
array([3])
array([3], dtype=int64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you are adding the 'dtype=int64' here? I don't see that in the output of my console.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears in my console, but I already delete them in 6ffdac7


>>> x.searchsorted([0, 4])
array([0, 3])
array([0, 3], dtype=int64)

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

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

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

>>> x.searchsorted('bread')
array([1]) # Note: an array, not a scalar
array([1], dtype=int64) # Note: an array, not a scalar

>>> x.searchsorted(['bread'])
array([1])

>>> x.searchsorted(['bread', 'eggs'])
array([1, 4])

>>> x.searchsorted(['bread', 'eggs'], side='right')
array([3, 4]) # eggs before milk
>>> x.searchsorted(['bread'], side='right')
array([3], dtype=int64)
""")

@Substitution(klass='IndexOpsMixin')
Expand Down