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

feat(python): validate Enum categories #13356

Merged
merged 5 commits into from
Jan 2, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jan 1, 2024

Split-out from #13345, and contains only the category-validation checks.
Prevents creation of invalid Enums (eg: with categories of the wrong type or duplicate values).

Examples

Category type check:

pl.Enum([1.234, 5.678])
# TypeError: Enum categories must be strings; found 1.234

Category uniqueness check:

pl.Enum(["misc", "value", "value", "other"])
# ValueError: Enum categories must be unique; found 1 duplicates, eg: 'value'

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Jan 1, 2024
Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently I am in a nitpicky mood today 😬

Nice to check for duplicates and stringiness, just some comments about the implementation though.

py-polars/polars/datatypes/classes.py Outdated Show resolved Hide resolved
py-polars/polars/datatypes/classes.py Outdated Show resolved Hide resolved
py-polars/polars/datatypes/classes.py Outdated Show resolved Hide resolved
py-polars/polars/datatypes/classes.py Outdated Show resolved Hide resolved
@alexander-beedie
Copy link
Collaborator Author

Apparently I am in a nitpicky mood today 😬

Didn't happen to make this your New Year's resolution?
Off to a good start if so! 🤣

Copy link
Member

@stinodego stinodego left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to merge if CI passes 👍

@ritchie46 ritchie46 merged commit 2a19d22 into pola-rs:main Jan 2, 2024
14 checks passed
@alexander-beedie alexander-beedie deleted the validate-enum-categories branch January 2, 2024 12:49
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 python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants