Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: Infer enums as categories #62207

Open
Open
Labels
Enhancement Needs TriageIssue that has not been reviewed by a pandas team member
@JensHeinrich

Description

Feature Type

  • Adding new functionality to pandas

  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Enhancement Needs TriageIssue that has not been reviewed by a pandas team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /