Skip to content

Commit

Permalink
Add autogenerated schemas.py.
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion committed Sep 12, 2023
1 parent d76ae48 commit bcb893f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions python/ribasim/ribasim/schemas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""
Generate Pandera Schemas from all autogenerated Pydantic Models
These classes have Schema as a postfix, so Ribasim.models.PumpStatic
becomes Ribasim.node_types.PumpStaticSchema.
"""
import inspect
import sys

import pandera as pa
from pandera.engines.pandas_engine import PydanticModel

from ribasim import models


def gen_schema(name, cls):
classname = f"{name}Schema"
setattr(
sys.modules[__name__],
classname,
type(
classname,
(pa.DataFrameModel,),
{
"Config": type(
f"{classname}.Config",
(),
{"dtype": PydanticModel(cls), "coerce": True},
)
},
),
)


for name, cls in inspect.getmembers(models, inspect.isclass):
gen_schema(name, cls)

0 comments on commit bcb893f

Please sign in to comment.