Feature Type
-
[ ] Adding new functionality to pandas
-
[x] Changing existing functionality in pandas
-
[ ] Removing existing functionality in pandas
Problem Description
I wish enum types like StrEnum
would be recognized as Categories by the type guessing functions, e.g. infer_objects
or convert_dtypes
as there is more information there then python[string]
Feature Description
With a frame as follows
from enum import StrEnum
import pandas as pd
class MyEnum(StrEnum):
A="a"
B="b"
C="c"
df=pd.json_normalize([{"k": x } for x in MyEnum if x !=MyEnum.C]).infer_objects()
df.dtypes
should return
k category
dtype: object
instead of
k object
dtype: object
and the category should contain all enum values as they are used for plots.
Alternative Solutions
Manually specify a category for every enum-based column
Additional Context
Maybe the EnumCategories types could even be global like polars so merging on these categories is quicker.
Comment From: jbrockmendel
I’d be fine with this if you’d like to open a PR. I think I’ve seen similar issues before.