Skip to content

MAINT: Standardize searchsorted signature #22672

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 1 commit into from
Sep 15, 2018
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.24.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ Deprecations
- :func:`pandas.read_table` is deprecated. Instead, use :func:`pandas.read_csv` passing ``sep='\t'`` if necessary (:issue:`21948`)
- :meth:`Series.str.cat` has deprecated using arbitrary list-likes *within* list-likes. A list-like container may still contain
many ``Series``, ``Index`` or 1-dimensional ``np.ndarray``, or alternatively, only scalar values. (:issue:`21950`)
- :meth:`FrozenNDArray.searchsorted` has deprecated the ``v`` parameter in favor of ``value`` (:issue:`14645`)

.. _whatsnew_0240.prior_deprecations:

Expand Down
24 changes: 14 additions & 10 deletions pandas/core/indexes/frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np
from pandas.core.base import PandasObject
from pandas.util._decorators import deprecate_kwarg
from pandas.core.dtypes.cast import coerce_indexer_dtype
from pandas.io.formats.printing import pprint_thing

Expand Down Expand Up @@ -117,10 +118,10 @@ def __unicode__(self):
quote_strings=True)
return "%s(%s, dtype='%s')" % (type(self).__name__, prepr, self.dtype)

def searchsorted(self, v, side='left', sorter=None):
@deprecate_kwarg(old_arg_name="v", new_arg_name="value")
def searchsorted(self, value, side="left", sorter=None):
"""
Find indices where elements of v should be inserted
in a to maintain order.
Find indices to insert `value` so as to maintain order.

For full documentation, see `numpy.searchsorted`

Expand All @@ -129,17 +130,20 @@ def searchsorted(self, v, side='left', sorter=None):
numpy.searchsorted : equivalent function
"""

# we are much more performant if the searched
# indexer is the same type as the array
# this doesn't matter for int64, but DOES
# matter for smaller int dtypes
# https://github.com/numpy/numpy/issues/5370
# We are much more performant if the searched
# indexer is the same type as the array.
#
# This doesn't matter for int64, but DOES
# matter for smaller int dtypes.
#
# xref: https://github.com/numpy/numpy/issues/5370
try:
v = self.dtype.type(v)
value = self.dtype.type(value)
except:
pass

return super(FrozenNDArray, self).searchsorted(
v, side=side, sorter=sorter)
value, side=side, sorter=sorter)


def _ensure_frozen(array_like, categories, copy=False):
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/indexes/test_frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ def test_values(self):
assert isinstance(self.container, FrozenNDArray)
tm.assert_numpy_array_equal(self.container.values(), original)
assert vals[0] == n

def test_searchsorted(self):
expected = 2
assert self.container.searchsorted(7) == expected

with tm.assert_produces_warning(FutureWarning):
assert self.container.searchsorted(v=7) == expected