Skip to content

How to use pandera in conjunction with typeguard and/or as a type checker for the other arguments? #837

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

You must be logged in to vote

If you really care about types, then you can actually use pandera.typing.DataFrame[Schema](data) (where data is some valid data you want for instantiating the dataframe). In this case, the types should match and typeguard should stop complaining.

You can think of pandera.typing.DataFrame[Schema](...) as a schema-typed dataframe. Initializing a dataframe like this basically validates the data coming in at initialization.

@typeguard.typechecked
@pa.check_types
def some_function(df: pa.typing.DataFrame[Schema], some_arg: int) -> None:
    ...

# when you invoke the function, make sure to pass in the schema-typed dataframe
some_function(pa.typing.DataFrame[Schema](...))

Although you're not us…

Replies: 6 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
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
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #836 on April 21, 2022 12:55.