BUG: CategoricalIndex.where nulling out non-categories by jbrockmendel · Pull Request #37977 · pandas-dev/pandas (original) (raw)
ci = CategoricalIndex(["a", "b", "c", "d"])
mask = np.array([True, False, True, False])
>>> ci.where(mask, 2)
CategoricalIndex(['a', nan, 'c', nan], categories=['a', 'b', 'c', 'd'], ordered=False, dtype='category')
This makes that call raise instead.
Index.where is only used in one place in reshape.merge. Might be worth deprecating+privatizing.