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

strict=True is not very strict on the index #1493

Open
smarie opened this issue Feb 12, 2024 · 0 comments
Open

strict=True is not very strict on the index #1493

smarie opened this issue Feb 12, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@smarie
Copy link
Contributor

smarie commented Feb 12, 2024

Hi, first of all thanks for this great library !

I today found out that I had a non-validated-enough dataframe, even if I was using strict=True. This was due to the fact that strict=True does not imply any kind of checks on the index.

Here is an example :

class FooModel(pa.DataFrameModel):
    a: pa.typing.Series[int]

    class Config:
        strict = True

As a user, when I run FooModel.validate(df), since I added strict=True, I would expect that any error or missing aspect in FooModel leads to an exception being raised. At the contrary, if I do not see any exception, that leads me to think that my FooModel is correct.

Yet,

df = pd.DataFrame(index=["hello"], data={"a": [1]})
df.index.name = "foo"
FooModel.validate(df)

does not raise any error. It breaks somehow the semantics of strict=True in my opinion, as it leaves some room for flexibility in the dataframe to be validated. In this example the non-None name on the index of df, and the fact that the index has dtype object. Do you agree ?

I would suggest to modify strict=True to perform the following: when the schema does not contain any specification about the index, validate that the index is the default pandas index (a rangeindex with no name).

@smarie smarie added the bug Something isn't working label Feb 12, 2024
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

1 participant