Skip to content

Commit

Permalink
Fix ValidationError from inplace set_geometry
Browse files Browse the repository at this point in the history
```
ValidationError                           Traceback (most recent call last)
File a:\repo\ribasim\Ribasim\models\see.py:1
----> 1 ribasim_testmodels.trivial_model()

File A:\repo\ribasim\Ribasim\python\ribasim_testmodels\ribasim_testmodels\trivial.py:9, in trivial_model()
      7 def trivial_model() -> Model:
      8     """Trivial model with just a basin, tabulated rating curve and terminal node."""
----> 9     model = Model(
     10         starttime="2020-01-01",
     11         endtime="2021-01-01",
     12         crs="EPSG:28992",
     13         results=Results(subgrid=True, compression=False),
     14         use_validation=True,
     15     )
     17     # Convert steady forcing to m/s
     18     # 2 mm/d precipitation, 1 mm/d evaporation
     19     precipitation = 0.002 / 86400

File a:\repo\ribasim\Ribasim\.pixi\envs\dev\Lib\site-packages\pydantic\main.py:214, in BaseModel.__init__(self, **data)
    212 # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    213 __tracebackhide__ = True
--> 214 validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    215 if self is not validated_self:
    216     warnings.warn(
    217         'A custom validator is returning a value other than `self`.\n'
    218         "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
    219         'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
    220         stacklevel=2,
    221     )

ValidationError: 1 validation error for Model
  Value error, Can't do inplace setting when converting from DataFrame to GeoDataFrame [type=value_error, input_value={'starttime': '2020-01-01... 'use_validation': True}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.10/v/value_error
```
  • Loading branch information
visr committed Dec 5, 2024
1 parent 09f6d74 commit e370a5d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion python/ribasim/ribasim/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def _set_node_parent(self) -> "Model":
def _ensure_edge_table_is_present(self) -> "Model":
if self.edge.df is None:
self.edge.df = GeoDataFrame[EdgeSchema](index=pd.Index([], name="edge_id"))
self.edge.df.set_geometry("geometry", inplace=True, crs=self.crs)
self.edge.df = self.edge.df.set_geometry("geometry", crs=self.crs)
return self

@model_validator(mode="after")
Expand Down

0 comments on commit e370a5d

Please sign in to comment.