Skip to content

Verification by condition #957

Answered by cosmicBboy
RuslanGadzhiev asked this question in Q&A
Discussion options

You must be logged in to vote

hi @RuslanGadzhiev, you'll have to create dataframe-level checks: https://pandera.readthedocs.io/en/stable/checks.html#wide-checks

For your use case, that would look something like:

import pandera as pa

def custom_check(df):
    # create an index-aligned series of True values
    check_output = pd.Series(True, index=df.index)

    # replace True values with corresponding entries in col2 < 100 where col1 is NA
    return check_output.where(df["col1"].isna(), df["col2"] < 100)

pa.DataFrameSchema(
    columns={...},
    checks=pa.Check(custom_check)
)

If you're using the pa.SchemaModel API, this would look like:

class Schema(pa.SchemaModel):
    col1: pa.typing.Series[float]
    col2: pa.t…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by RuslanGadzhiev
Comment options

You must be logged in to vote
1 reply
@cosmicBboy
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants