Skip to content

Commit efc53b6

Browse files
Update model.py
Signed-off-by: Nathan McDougall <[email protected]>
1 parent 57d8269 commit efc53b6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pandera/api/pandas/model.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,18 @@ def _convert_extras_to_checks(extras: Dict[str, Any]) -> List[Check]:
124124

125125
return checks
126126

127+
class MetaDataFrameModel(MetaModel):
128+
"""A metaclass for DataFrameModel to provide iter support."""
129+
130+
def to_schema(cls) -> DataFrameSchema:
131+
"""Create :class:`~pandera.DataFrameSchema` from the class."""
132+
raise NotImplementedError
133+
134+
def __iter__(cls) -> Iterable[str]:
135+
"""Iterate over the fields of the schema"""
136+
return iter(cls.to_schema().columns)
127137

128-
class DataFrameModel(BaseModel):
138+
class DataFrameModel(BaseModel, metaclass=MetaDataFrameModel):
129139
"""Definition of a :class:`~pandera.api.pandas.container.DataFrameSchema`.
130140
131141
*new in 0.5.0*

0 commit comments

Comments
 (0)