I'm trying to create a Cerberus validation schema to validate a set of data in a Pandas dataframe. One of the columns should only validate on the following data:
- numbers
- NaN (this is Numpy's floating-point representation of Not a Number, and how I'm indicating null in my data)
I read the accepted answer on this post about using anyof
and I structured my schema in the same way:
import numpy as np
schema = {
'some_field': {
'schema': {
'anyof': [
{
'type': 'float',
'allowed': [
np.nan
]
},
{
'type': 'number'
}
]
}
}
}
But when I try to validate against this schema, it's returning True for documents where the field is not a number (Strings, booleans). For example:
>>> v = Validator(schema)
>>> doc = {'some_field': 'hi'}
>>> v.validate(doc)
True
>> doc = {'some_field': False}
>>> v.validate(doc)
True
It seems like this will always return true. Does anyone have any idea why it's doing this?