BUG: CategoricalIndex.searchsorted doesn't return a scalar if input was scalar by fjetter · Pull Request #21019 · pandas-dev/pandas (original) (raw)

CategoricalIndex.searchsorted returns the wrong shape for scalar input. Numpy arrays and all other index types return a scalar if the input is a scalar, but the CategoricalIndex does not

For example

>>> import numpy as np
>>> np.array([1, 2, 3]).searchsorted(1)
0
>>> np.array([1, 2, 3]).searchsorted([1])
array([0])
>>> import pandas as pd
>>> pd.Index([1, 2, 3]).searchsorted(1)
0
>>> pd.Index([1, 2, 3]).searchsorted([1])
array([0])

This issue also affects slicing on sorted/ordered categoricals, which is why I've written another test for the slicing.