From d93f46447531c5983b05687b268f3983776459d4 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Mon, 29 Sep 2014 20:03:36 +0200 Subject: [PATCH] FIX: Add Categorical.searchsorted stub For https://github.com/pydata/pandas/pull/7447, add a searchsorted stub, which simple raises NotImplementedError, so taht we raise a more clear error than attribute not found. --- pandas/core/categorical.py | 3 +++ pandas/tests/test_categorical.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/pandas/core/categorical.py b/pandas/core/categorical.py index d404601bcafa1..d2708890c5ec2 100644 --- a/pandas/core/categorical.py +++ b/pandas/core/categorical.py @@ -726,6 +726,9 @@ def T(self): def nbytes(self): return self._codes.nbytes + self._categories.values.nbytes + def searchsorted(self, v, side='left', sorter=None): + raise NotImplementedError("See https://github.com/pydata/pandas/issues/8420") + def isnull(self): """ Detect missing values diff --git a/pandas/tests/test_categorical.py b/pandas/tests/test_categorical.py index d4cf687486cfb..e05d7285592aa 100644 --- a/pandas/tests/test_categorical.py +++ b/pandas/tests/test_categorical.py @@ -889,6 +889,15 @@ def test_nbytes(self): exp = cat._codes.nbytes + cat._categories.values.nbytes self.assertEqual(cat.nbytes, exp) + def test_searchsorted(self): + + # See https://github.com/pydata/pandas/issues/8420 + # TODO: implement me... + cat = pd.Categorical([1,2,3]) + def f(): + cat.searchsorted(3) + self.assertRaises(NotImplementedError, f) + def test_deprecated_labels(self): # TODO: labels is deprecated and should be removed in 0.18 or 2017, whatever is earlier cat = pd.Categorical([1,2,3, np.nan], categories=[1,2,3])