Skip to content

Commit

Permalink
Merge branch 'master' into df_set_index_warn
Browse files Browse the repository at this point in the history
  • Loading branch information
h-vetinari authored Sep 15, 2018
2 parents 229e72d + 1c500fb commit fecb731
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 11 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 @@ -561,6 +561,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
2 changes: 1 addition & 1 deletion pandas/tests/frame/test_alter_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_set_index_raise(self, frame_of_index_cols, drop, append):
# forbidden type in list, e.g. set
with tm.assert_raises_regex(TypeError, rgx):
df.set_index(['A', df['A'], set(df['A'])],
drop=drop, append=append)
drop=drop, append=append)h

def test_construction_with_categorical_index(self):
ci = tm.makeCategoricalIndex(10)
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 fecb731

Please sign in to comment.