From 07291eab6bb4b56c6983753c74a2a5070c7ae573 Mon Sep 17 00:00:00 2001 From: tp Date: Mon, 28 Jan 2019 22:52:31 +0000 Subject: [PATCH] Guard against IntegerArray + cleanups --- doc/source/whatsnew/v0.25.0.rst | 4 ++-- pandas/core/algorithms.py | 6 +++--- pandas/core/common.py | 5 ++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/doc/source/whatsnew/v0.25.0.rst b/doc/source/whatsnew/v0.25.0.rst index 89b7eed06dbddf..3ed1094a019647 100644 --- a/doc/source/whatsnew/v0.25.0.rst +++ b/doc/source/whatsnew/v0.25.0.rst @@ -60,8 +60,8 @@ Performance Improvements - Significant speedup in `SparseArray` initialization that benefits most operations, fixing performance regression introduced in v0.20.0 (:issue:`24985`) - `DataFrame.to_stata()` is now faster when outputting data with any string or non-native endian columns (:issue:`25045`) -- Improved performance of :meth:`Series.searchsorted`. The speedup is especially large when the dtype is int8/int16/int32 and the searched key is within - the integer bounds for the dtype(:issue:`22034`) +- Improved performance of :meth:`Series.searchsorted`. The speedup is especially large when the dtype is + int8/int16/int32 and the searched key is within the integer bounds for the dtype(:issue:`22034`) .. _whatsnew_0250.bug_fixes: diff --git a/pandas/core/algorithms.py b/pandas/core/algorithms.py index 10ebf2ea4469ce..3ae4a1345fe51e 100644 --- a/pandas/core/algorithms.py +++ b/pandas/core/algorithms.py @@ -1724,9 +1724,9 @@ def func(arr, indexer, out, fill_value=np.nan): return out -# ---- # +# ------------ # # searchsorted # -# ---- # +# ------------ # def searchsorted(arr, value, side="left", sorter=None): """ @@ -1774,7 +1774,7 @@ def searchsorted(arr, value, side="left", sorter=None): if sorter is not None: sorter = ensure_platform_int(sorter) - if is_integer_dtype(arr) and ( + if isinstance(arr, np.ndarray) and is_integer_dtype(arr) and ( is_integer(value) or is_integer_dtype(value)): from .arrays.array_ import array # if `arr` and `value` have different dtypes, `arr` would be diff --git a/pandas/core/common.py b/pandas/core/common.py index 099e0947a33df7..5b83cb344b1e70 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -13,7 +13,8 @@ import numpy as np from pandas._libs import lib, tslibs -from pandas.compat import PY36, OrderedDict, iteritems +import pandas.compat as compat +from pandas.compat import PY36, iteritems from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike from pandas.core.dtypes.common import ( @@ -22,8 +23,6 @@ from pandas.core.dtypes.inference import _iterable_not_string from pandas.core.dtypes.missing import isna, isnull, notnull # noqa -from pandas import compat - class SettingWithCopyError(ValueError): pass