Skip to content

REGR: empty CatgoricalIndex constructor by passing no data (but passing categories) no longer working #38944

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

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:

cc @jbrockmendel

Metadata

Metadata

Assignees

No one assigned

    Labels

    CategoricalCategorical Data TypeNeeds DiscussionRequires discussion from core team before further actionRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions