Skip to content

Checking bad datatypes and invalid values with a single schema. #619

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

You must be logged in to vote

hey @JiriFranek92 good question!

The reason you're getting the TypeError is that the built-in checks use vectorized implementations of checks, so Check.greater_than(0) is basically series > 0. This means that if one of the values in a series does not support the vectorized operation, it'll raise that TypeError. pandera only reports the runtime errors raised by pandas. pandera does this to take advantage of the speed gains from using the native pandas vectorized operations (the limitation being that it doesn't out-right support your desired behavior).

To get the desired behavior you'll have to use element_wise checks and explicitly handle the TypeError to return a False value.

import pandas 

Replies: 2 comments 2 replies

Comment options

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

You must be logged in to vote
2 replies
@JiriFranek92
Comment options

@jeffzi
Comment options

jeffzi Sep 20, 2021
Collaborator

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