Skip to content

Commit

Permalink
MAINT: Standardize searchsorted signature
Browse files Browse the repository at this point in the history
"values" is the law of the land. This usage
is internal, hence why we aren't going
through a deprecation cycle.

xref pandas-devgh-14645.

Follow-up to pandas-devgh-15601.
  • Loading branch information
gfyoung committed Sep 13, 2018
1 parent c040353 commit c162b3b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
21 changes: 12 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,9 @@ 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):
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 +129,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
4 changes: 4 additions & 0 deletions pandas/tests/indexes/test_frozen.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ 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

0 comments on commit c162b3b

Please sign in to comment.