unionai-oss / pandera

A light-weight, flexible, and expressive statistical data testing library
https://www.union.ai/pandera
MIT License
3.27k stars 305 forks source link

SchemaModel does not support empty data type #522

Closed jeffzi closed 2 years ago

jeffzi commented 3 years ago

SchemaModel does not support annotations without a data type, which is supported by DataFrameSchema.

Code Sample, a copy-pastable example

import pandera as pa

pa.DataFrameSchema({"a": pa.Column()})  # works
#> <Schema DataFrameSchema(columns={'a': <Schema Column(name=a, type=None)>}, checks=[], index=None, coerce=False, pandas_dtype=None,strict=False,name=None,ordered=False)>

class Schema(pa.SchemaModel):
    column_a: pa.typing.Series

Schema.to_schema()
#> Traceback (most recent call last):
#> <ipython-input-6-87d3c11c1990> in <module>
#> ----> 1 Schema.to_schema()
#> XX/pandera/pandera/model.py in to_schema(cls)
#>     195         cls.__dataframe_checks__ = df_custom_checks + df_registered_checks
#>     196 
#> --> 197         columns, index = cls._build_columns_index(
#>     198             cls.__fields__, cls.__checks__, **mi_kwargs
#>     199         )
#> ~XX/model.py in _build_columns_index(cls, fields, checks, **multiindex_kwargs)
#>     319                 indices.append(index)
#>     320             else:
#> --> 321                 raise SchemaInitError(
#>     322                     f"Invalid annotation '{field_name}: {annotation.raw_annotation}'"
#>     323                 )
#> SchemaInitError: Invalid annotation 'column_a: <class 'pandera.typing.Series'>'

Expected behavior

SchemaModel should match the DataFrameSchema API and the data type should be optional.

cosmicBboy commented 3 years ago

hey @jeffzi I don't think this addresses the question in #521... tho I think it would be a nice feature to have, so feel free to make a PR for it!

cosmicBboy commented 3 years ago

@jeffzi FYI #594 added support for the any type, it probably still makes sense to support an empty pa.typing.Series type, so this issue is still valid

jeffzi commented 2 years ago

Fixed by #602