Skip to content

Commit e553898

Browse files
committed
changed according to comments
1 parent 65cc427 commit e553898

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

doc/source/whatsnew/v0.24.0.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,7 @@ Categorical
557557
^^^^^^^^^^^
558558

559559
- Bug in :meth:`Categorical.from_codes` where ``NaN`` values in `codes` were silently converted to ``0`` (:issue:`21767`). In the future this will raise a ``ValueError``. Also changes the behavior of `.from_codes([1.1, 2.0])`.
560-
- :meth:`Categorical.searchsorted` and :meth:`CategoricalIndex.searchsorted`
561-
now work on unordered categoricals also (:issue:`21667`)
560+
- :meth:`Categorical.searchsorted` and :meth:`CategoricalIndex.searchsorted` now work on unordered categoricals also (:issue:`21667`)
562561
-
563562

564563
Datetimelike

pandas/core/base.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1169,13 +1169,12 @@ def factorize(self, sort=False, na_sentinel=-1):
11691169
11701170
.. note::
11711171
1172-
The %(klass)s *must* be monotonically sorted, else wrong
1173-
index locations may be returned. Pandas does *not* check
1174-
this for you.
1172+
The %(klass)s *must* be monotonically sorted, otherwise
1173+
wrong locations will likely be returned. Pandas does *not*
1174+
check this for you.
11751175
11761176
You can check sortedness by calling
1177-
``is_monotonic_increasing/is_monotonic_decreasing`` on the
1178-
Series or Index.
1177+
:meth:`%(klass)s.is_monotonic_increasing`.
11791178
11801179
Parameters
11811180
----------
@@ -1214,7 +1213,7 @@ def factorize(self, sort=False, na_sentinel=-1):
12141213
dtype: int64
12151214
12161215
>>> x.searchsorted(4)
1217-
array([3]) # Note: an array, not a scalar
1216+
array([3])
12181217
12191218
>>> x.searchsorted([0, 4])
12201219
array([0, 3])

pandas/tests/arrays/categorical/test_analytics.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -70,46 +70,45 @@ def test_mode(self, values, categories, exp_mode):
7070
exp = Categorical(exp_mode, categories=categories, ordered=True)
7171
tm.assert_categorical_equal(res, exp)
7272

73-
@pytest.mark.parametrize("ordered", [True, False])
7473
def test_searchsorted(self, ordered):
7574
# https://github.com/pandas-dev/pandas/issues/8420
7675
# https://github.com/pandas-dev/pandas/issues/14522
7776

78-
c = Categorical(['cheese', 'milk', 'apple', 'bread', 'bread'],
79-
categories=['cheese', 'milk', 'apple', 'bread'],
80-
ordered=ordered)
81-
s = Series(c)
77+
cat = Categorical(['cheese', 'milk', 'apple', 'bread', 'bread'],
78+
categories=['cheese', 'milk', 'apple', 'bread'],
79+
ordered=ordered)
80+
ser = Series(cat)
8281

8382
# Searching for single item argument, side='left' (default)
84-
res_cat = c.searchsorted('apple')
85-
res_ser = s.searchsorted('apple')
83+
res_cat = cat.searchsorted('apple')
84+
res_ser = ser.searchsorted('apple')
8685
exp = np.array([2], dtype=np.intp)
8786
tm.assert_numpy_array_equal(res_cat, exp)
8887
tm.assert_numpy_array_equal(res_ser, exp)
8988

9089
# Searching for single item array, side='left' (default)
91-
res_cat = c.searchsorted(['bread'])
92-
res_ser = s.searchsorted(['bread'])
90+
res_cat = cat.searchsorted(['bread'])
91+
res_ser = ser.searchsorted(['bread'])
9392
exp = np.array([3], dtype=np.intp)
9493
tm.assert_numpy_array_equal(res_cat, exp)
9594
tm.assert_numpy_array_equal(res_ser, exp)
9695

9796
# Searching for several items array, side='right'
98-
res_cat = c.searchsorted(['apple', 'bread'], side='right')
99-
res_ser = s.searchsorted(['apple', 'bread'], side='right')
97+
res_cat = cat.searchsorted(['apple', 'bread'], side='right')
98+
res_ser = ser.searchsorted(['apple', 'bread'], side='right')
10099
exp = np.array([3, 5], dtype=np.intp)
101100
tm.assert_numpy_array_equal(res_cat, exp)
102101
tm.assert_numpy_array_equal(res_ser, exp)
103102

104103
# Searching for a single value that is not from the Categorical
105-
pytest.raises(ValueError, lambda: c.searchsorted('cucumber'))
106-
pytest.raises(ValueError, lambda: s.searchsorted('cucumber'))
104+
pytest.raises(ValueError, lambda: cat.searchsorted('cucumber'))
105+
pytest.raises(ValueError, lambda: ser.searchsorted('cucumber'))
107106

108107
# Searching for multiple values one of each is not from the Categorical
109108
pytest.raises(ValueError,
110-
lambda: c.searchsorted(['bread', 'cucumber']))
109+
lambda: cat.searchsorted(['bread', 'cucumber']))
111110
pytest.raises(ValueError,
112-
lambda: s.searchsorted(['bread', 'cucumber']))
111+
lambda: ser.searchsorted(['bread', 'cucumber']))
113112

114113
def test_unique(self):
115114
# categories are reordered based on value when ordered=False

0 commit comments

Comments
 (0)