Closed roshcagra closed 2 years ago
You need to use check_name
:
import pandera as pa
from pandera.typing import Index
class MySchemaModel(pa.SchemaModel):
my_index: Index[pa.String] = pa.Field(coerce=True, check_name=True)
print(MySchemaModel.to_schema().index)
#> <Schema Index(name=my_index, type=DataType(str))>
The reason is that naming a pandera.Index will automatically activate name validation. In a SchemaModel, you have to name the class attribute to satisfy python's syntax. check_name
is there to not force users to name the index of the DataFrames they want to validate.
Describe the bug When creating a
SchemaModel
, if you specify anIndex
and try to retrieve its name, the name is set toNone
instead of the field name.Code Sample, a copy-pastable example
Expected behavior
I would expect the Index to set its name as the field name from the
SchemaModel
:Desktop (please complete the following information):
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.