Skip to content

Commit

Permalink
fix: SQLModel table model not validated (#1696)
Browse files Browse the repository at this point in the history
* explicitly validate row dict

Signed-off-by: Alp Aribal <alparbal@gmail.com>

* move self.type into init

Signed-off-by: Alp Aribal <alparbal@gmail.com>

* rm unnecessary pylint ignore

Signed-off-by: Alp Aribal <alparbal@gmail.com>

* revert change, use pylint disable

Signed-off-by: Alp Aribal <alparbal@gmail.com>

* rm type from init, add back type ignore with specific rule

Signed-off-by: Alp Aribal <alparbal@gmail.com>

---------

Signed-off-by: Alp Aribal <alparbal@gmail.com>
Co-authored-by: Niels Bantilan <niels.bantilan@gmail.com>
  • Loading branch information
AlpAribal and cosmicBboy authored Jul 20, 2024
1 parent 1ec5c31 commit 89683c9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pandera/engines/pandas_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ def from_parametrized_dtype(cls, pd_dtype: pd.IntervalDtype):
class PydanticModel(DataType):
"""A pydantic model datatype applying to rows in a dataframe."""

type: Type[BaseModel] = dataclasses.field(default=None, init=False) # type: ignore # noqa
type: Type[BaseModel] = dataclasses.field(default=None, init=False) # type: ignore[assignment]
auto_coerce = True

# pylint:disable=super-init-not-called
Expand All @@ -1140,11 +1140,11 @@ def _coerce_row(row):
cases.
"""
try:
# pylint: disable=not-callable
# pylint: disable=no-member
if PYDANTIC_V2:
row = self.type(**row).model_dump()
row = self.type.model_validate(row).model_dump()
else:
row = self.type(**row).dict()
row = self.type.parse_obj(row).dict()
row["failure_cases"] = np.nan
except ValidationError as exc:
row["failure_cases"] = {
Expand Down

0 comments on commit 89683c9

Please sign in to comment.