Skip to content

ENH: Add a .to_pd_categorical_dtype() to dataclasses decorated with @categorical #242

@hmgaudecker

Description

@hmgaudecker

We currently do this in simulation.result:

def _codes_to_categorical(
    *,
    codes: pd.Series,
    categories: tuple[str, ...],
) -> pd.Categorical | pd.Series:

but users may well want to check their own data against this. So it would be neat to have a pd.CategoricalDtype returned from something like:

@categorical
class WorkingStatus:
    retired: int
    working: int

WorkingStatus.to_categorical_dtype()

Added benefit would be that we could use it on any data even if it might not have all outcomes and the dtype will always be correct.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions