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): Improved error message on invalid Python Enum init #20060

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Nov 28, 2024

Improves an error message that could be raised when initialising Polars Enum from an unsuitable Python Enum type; instead of using the generic enum class name we now reference the specific enum, eg:

Also: minor tweak to pl.from_repr Series regex (4 -> 2).
(apparently some editors collapse the usual leading four spaces to two).

Example

import polars as pl
import enum

class Color(enum.IntEnum):
    RED = enum.auto()
    GREEN = enum.auto()
    BLUE = enum.auto()

dtype = pl.Enum(Color)

Before: TypeError: Enum categories must be strings; Python `enum.IntEnum` values are integers
After: TypeError: Enum categories must be strings; `Color` values are integers

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

codecov bot commented Nov 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.53%. Comparing base (9513c52) to head (f25c86e).
Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #20060   +/-   ##
=======================================
  Coverage   79.52%   79.53%           
=======================================
  Files        1563     1563           
  Lines      217180   217180           
  Branches     2461     2461           
=======================================
+ Hits       172714   172731   +17     
+ Misses      43907    43890   -17     
  Partials      559      559           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46 ritchie46 merged commit ccaf682 into pola-rs:main Nov 29, 2024
25 checks passed
@alexander-beedie alexander-beedie deleted the enum-err-msg branch November 29, 2024 08:06
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.

2 participants