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

Polars Enum does not work for Polars verion >=1.0.0 #1768

Closed
3 tasks done
butterlyn opened this issue Jul 31, 2024 · 1 comment · Fixed by #1798
Closed
3 tasks done

Polars Enum does not work for Polars verion >=1.0.0 #1768

butterlyn opened this issue Jul 31, 2024 · 1 comment · Fixed by #1798
Labels
bug Something isn't working

Comments

@butterlyn
Copy link

butterlyn commented Jul 31, 2024

Describe the bug
pl.Enum does not work for Polars version >=1.0.0

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of pandera.
  • (optional) I have confirmed this bug exists on the main branch of pandera.

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandera.polars as pa
import polars as pl

yes_no_enum_dtype = pl.Enum(categories=["yes", "no"])

class MyDataFrameModel(pa.DataFrameModel):
    answer: yes_no_enum_dtype

df: pl.DataFrame = pl.DataFrame(data={"answer": ["yes", "no", "no"]}, schema={"answer": yes_no_enum_dtype})

MyDataFrameModel.validate(df)
TypeError: cannot parse input of type 'Enum' into Polars data type: Enum(categories=['yes', 'no'])

Note that this only happens when Polars version is >=1.0.0, and runs without error if polars verion is <1.0.0 (tested on 0.20.31)

Desktop (please complete the following information):

  • OS: Windows

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

I suspect the cause of the issue is that the annotation is not recognized as a Polars dtype here:

is_polars_dtype = inspect.isclass(

Though this doesn't explain why the error only occurs for Polars version >=1.0.0.

import inspect
import polars as pl

yes_no_enum_dtype = pl.Enum(categories=["yes", "no"])

print(inspect.isclass(yes_no_enum_dtype))
False

Also, this issue similar to #1767, but that issue is a feature request, while this issue is about a bug triggered by Polars 1.0.0 for an existing Pandera feature.

edit: clarify that this was done with Pandera version v0.20.3

@butterlyn butterlyn added the bug Something isn't working label Jul 31, 2024
@butterlyn
Copy link
Author

Ran this on the main branch, the error message changes (compared to v0.20.3) to:

ImportError: cannot import name 'Check' from partially initialized module 'pandera.api.checks' (most likely due to a circular import) (C:\Users\nbutterly\Documents\Coding_2\pandera_testing\pandera\pandera\api\checks.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant