DataFrameSchema with column of type pa.Float will raise SchemaError on validating DataFrame with float32 column #541
Replies: 3 comments
-
Thanks for raising this, been encountering it myself. |
Beta Was this translation helpful? Give feedback.
-
Technically the documentation is correct, import numpy as np
import pandas as pd
print(np.float_)
#> <class 'numpy.float64'>
print(pd.Series([1.0], dtype="float").dtype)
#> float64 At the moment, Pandera only does strict dtype validation. Perhaps the documentation should be clearer? That said, I do think it would be helpful to be allow size-agnostic float, int and complex dtypes. For context, we are finalizing a refactor of how pandera handles dtypes (#369), and it is now a good time to introduce that kind of feature. I see multiple ways to go about it:
I favor 2. because it's more explicit and is not a breaking change. @cosmicBboy Thoughts? |
Beta Was this translation helpful? Give feedback.
-
@daavidstein the approach pandera takes is to (a) err on the explicit side rather than the implicit (a validation library with too much magic seems like an oxymoron 🙂) and (b) to be consistent with pandas/numpy behavior, so In [26]: pd.Series([1,2,3], dtype=float).dtype
Out[26]: dtype('float64')
In [27]: pd.Series([1,2,3], dtype="float").dtype
Out[27]: dtype('float64') Currently I'd recommend two approaches:
For for the future state of things, I think |
Beta Was this translation helpful? Give feedback.
-
Bug description
DataFrameSchema
with column of typepandera.Float
will raiseSchemaError
on validating DataFrame withfloat32
columnMinimal Failing Example
Expected behavior
Given that the pandera documentation states that
pandera.Float
corresponds tonumpy
float
the expectation is that a SchemaError is not raised for columns with typefloat16
,float32
,float64
, orfloat128
Additional context
Our dataset columns go through a transformation from
float128
tofloat32
and we would like to use the same schema for validation before and after the transformation.Beta Was this translation helpful? Give feedback.
All reactions