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

Data type validation at DataFrame Models initialization seems to be broken in v0.21.0 compared to v0.20.4 #1859

Open
2 of 3 tasks
hnomichith opened this issue Nov 20, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@hnomichith
Copy link

Describe the bug

After upgrading from Pandera 0.20.4 to 0.21.0, the data type validation at DataFrame Models initialization (cf this doc) seems to be broken: validating a wrong dataframe does not raise an error.

  • 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 pandas as pd
    from pandera import DataFrameModel
    from pandera.typing import DataFrame

    class ExampleModel(DataFrameModel):
        field1: str
        field2: float

    # This is supposed to crash, the schema is not respected.
    # This is raising validation error (as expected) in 0.20.4, but not in 0.21.0
    dataframe = DataFrame[ExampleModel](
        pd.DataFrame.from_dict(
            {
                "field3": [None, None, 1, None, 2],
            }
        )
    )

    # Only reached in 0.21.0
    print(dataframe)

Expected behavior

The data type validation should raise an error, and the line print(dataframe) shouldnot be reached.

Desktop (please complete the following information):

  • OS: Linux Mint
  • Version: 21.2
@hnomichith hnomichith added the bug Something isn't working label Nov 20, 2024
@hasanasim
Copy link

Data type validation is also broken on v0.21.0 when using the pa.check decorator and works fine on v0.20.4 e.g.

class MyModel(pa.DataFrameModel):
    my_type: object
    id: int

    @pa.check("my_type")
    def is_serialised_type(cls, t: object) -> bool:
        return isinstance(t, SerialisedType)

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

No branches or pull requests

2 participants