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

Closed
max-muoto opened this issue Nov 11, 2024 · 1 comment · Fixed by #19926
Closed

Support StrEnums in Enum Construction #19724

max-muoto opened this issue Nov 11, 2024 · 1 comment · Fixed by #19926
Assignees
Labels
accepted Ready for implementation 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
accepted Ready for implementation enhancement New feature or an improvement of an existing feature
Projects
Archived in project
4 participants