Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support StrEnums in Enum Construction #19724

Open
max-muoto opened this issue Nov 11, 2024 · 1 comment · May be fixed by #19725
Open

Support StrEnums in Enum Construction #19724

max-muoto opened this issue Nov 11, 2024 · 1 comment · May be fixed by #19725
Labels
enhancement New feature or an improvement of an existing feature

Comments

@max-muoto
Copy link
Contributor

Description

Right now, if you want to create Polars enum from a StrEnum you're required to first list convert it:

import enum

class PythonEnum(enum.StrEnum):
    A = "A"
    B = "B"
    C = "C"

e = pl.Enum(list(PythonEnum))
df = pl.DataFrame({"Col 1": ["A", "B", "C"]}, schema={"Col 1": e})

While easy enough, I don't see any reason why direct creation of Polars Enums from Python enums shouldn't be supported:

import enum

class PythonEnum(enum.StrEnum):
    A = "A"
    B = "B"
    C = "C"

e = pl.Enum(PythonEnum)
df = pl.DataFrame({"Col 1": ["A", "B", "C"]}, schema={"Col 1": e})
@max-muoto max-muoto added the enhancement New feature or an improvement of an existing feature label Nov 11, 2024
@Julian-J-S
Copy link
Contributor

why not go one step further and use the python enum directly? (should be possble?) 😄
This works for exmpale using python str / int / float

pl.DataFrame(
    {"a": [1], "b": [1], "c": [1]},
    schema={
        "a": pl.String,
        "b": str, # <<<<<
        "c": float, # <<<<<
    },
    strict=False,
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants