TYPING: Partial typing of Categorical by topper-123 · Pull Request #27318 · pandas-dev/pandas (original) (raw)
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an aside I was kind of curious why this couldn't be inferred more easily since it's really just a str and a CategoricalDtype that are allowed here. So ideally I thought isinstance(str)
and isinstance(self)
would be two possible branches.
I think the reason this wasn't laid out that way is to allow Categorical
objects to be passed as well, but doing so actually causes an error:
t = pd.CategoricalDtype(categories=['b', 'a'], ordered=True) c = pd.Categorical(['a','b','c','a','b','c'], ordered=True, categories=['c', 'b', 'a'])
t.update_dtype(c) Traceback (most recent call last): File "", line 1, in File "/Users/williamayd/clones/pandas/pandas/core/dtypes/dtypes.py", line 561, in update_dtype new_ordered = dtype._ordered AttributeError: 'Categorical' object has no attribute '_ordered'
cc @TomAugspurger for intent. If a bug maybe we drop this annotation for now and clean up with bug resolution