REGR: empty CatgoricalIndex constructor by passing no data (but passing categories) no longer working · Issue #38944 · pandas-dev/pandas (original) (raw)
See https://github.com/pandas-dev/pandas/pull/38614/files#r551313565
#38614 changed the CategoricalIndex constructor to disallow scalar values, but at the same time it also disallowed passing no values to create an empty index (which in practice means passing the default of None
):
In [17]: pd.CategoricalIndex(categories=['a', 'b'])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-17-6f0ae73d9374> in <module>
----> 1 pd.CategoricalIndex(categories=['a', 'b'])
~/scipy/pandas/pandas/core/indexes/category.py in __new__(cls, data, categories, ordered, dtype, copy, name)
187 dtype: Optional[Dtype] = None,
188 copy=False,
--> 189 name=None,
190 ):
191
TypeError: CategoricalIndex(...) must be called with a collection of some kind, None was passed
If we make this change, this is at least something that should be deprecated IMO (eg it breaks dask parquet reading).
But I am not sure if we should change it, since other constructors like Series()
allow similar creation of empty objects: