Skip to content

Commit

Permalink
DEPR: Standardize searchsorted signature
Browse files Browse the repository at this point in the history
"values" is the law of the land.

xref pandas-devgh-14645.

Follow-up to pandas-devgh-15601.
  • Loading branch information
gfyoung committed Sep 12, 2018
1 parent 73dd6ec commit 8d1b41d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
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 @@ -557,6 +557,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
22 changes: 13 additions & 9 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
# 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
#
# 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

0 comments on commit 8d1b41d

Please sign in to comment.