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

Cannot call get_metadata on a DataFrameModel if there is a Config without a metadata attribute #1640

Open
2 of 3 tasks
cbrummitt opened this issue May 13, 2024 · 0 comments
Open
2 of 3 tasks
Labels
bug Something isn't working

Comments

@cbrummitt
Copy link

Describe the bug
I have a DataFrameModel with a custom Config. When I tried to define a class method that returns a subset of columns with certain metadata, I found that I needed to either add metadata = None on my custom config or change the config to inherit from BaseConfig. It'd be nice to allow using column-level metadata without having to define schema-level metadata.

  • 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

Here's a minimal example that raises AttributeError: type object 'Config' has no attribute 'metadata':

import pandera as pa


class SchemaA(pa.DataFrameModel):
    foo: str = pa.Field(metadata=dict(include=True))
    bar: str = pa.Field()

    @classmethod
    def subset(cls) -> list[str]:
        return [
            column
            for column, metadata in cls.get_metadata()[str(cls)]["columns"].items()
            if metadata is not None and metadata.get("include")
        ]

    class Config:
        strict = True


print(SchemaA.subset())

Expected behavior

If we add metadata = None on Config or make the Config inherit from pandera.api.pandas.model_config.BaseConfig, then the snippet above produces the expected output of ["foo"].

Desktop (please complete the following information):

  • Version: pandera 0.19.2
@cbrummitt cbrummitt added the bug Something isn't working label May 13, 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