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

Groupby field does not get serialized. #1843

Open
2 of 3 tasks
baasman92 opened this issue Oct 29, 2024 · 0 comments
Open
2 of 3 tasks

Groupby field does not get serialized. #1843

baasman92 opened this issue Oct 29, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@baasman92
Copy link

Describe the bug
A clear and concise description of what the bug is.

  • 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.

You can follow the following snippet to reproduce the error:

Code Sample, a copy-pastable example

import pandera as pa
import pandera.extensions as extensions
import pandas as pd

from typing import Dict


@extensions.register_check_method(
    statistics=["group_a", "group_b"],
    check_type="groupby",
)
def groupby_check(dict_groups: Dict[str, pd.Series], *, group_a, group_b):
    return dict_groups[group_a].mean() > dict_groups[group_b].mean()


data = pd.DataFrame(
    {
        "values": [20, 10, 1, 15],
        "groups": list("xxyy"),
    }
)

schema = pa.DataFrameSchema(
    {
        "values": pa.Column(
            int,
            pa.Check.groupby_check(group_a="x", group_b="y", groupby="groups"),
        ),
        "groups": pa.Column(str),
    }
)

schema.to_yaml("/tmp/schema.yml")

serialized_schema = pa.DataFrameSchema.from_yaml("/tmp/schema.yml")

serialized_schema.validate(data)

Expected behavior

I would expect the dict_groups to be passed to the groupby_check function, but instead the entire series is passed without the groupby.

Desktop (please complete the following information):

  • Centos 7
  • Pandera version: 0.20.4
  • Python version: 3.10.9
@baasman92 baasman92 added the bug Something isn't working label Oct 29, 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