Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support pydantic v2 #673

Closed
wants to merge 7 commits into from
Closed

support pydantic v2 #673

wants to merge 7 commits into from

Conversation

visr
Copy link
Member

@visr visr commented Oct 17, 2023

I went a few steps further than mentioned in #382 (comment), but I get stuck, so it is probably better to continue after #630.

Main issues are that these nested default dicts are not appreciated by mypy: 50cf27f#diff-bdece7de80ef751956236e71b5aed3964311d59479f076c892d6745b0e30266d

The other one is that it doesn't like the optional DataFrame:

>       node = ribasim.Node(
            static=gpd.GeoDataFrame(
                data={
                    "type": node_type,
                    "name": [ribasim.utils.random_string() for _ in range(len(node_id))],
                },
                index=pd.Index(node_id, name="fid"),
                geometry=node_xy,
                crs="EPSG:28992",
            )
        )
E       pydantic_core._pydantic_core.ValidationError: 1 validation error for Node
E       static
E         Value error, Cannot use DataFrame as a pydantic type as its DataFrameModel cannot be converted to a DataFrameSchema.
E       Please revisit the model to address the following errors:
E       Found missing annotations: ['model_config'] [type=value_error, input_value=                     type...vc   POINT (6.000 1.000), input_type=GeoDataFrame]
E           For further information visit https://errors.pydantic.dev/2.4/v/value_error

python\ribasim_testmodels\ribasim_testmodels\basic.py:160: ValidationError

Would fix #382.

visr and others added 7 commits October 16, 2023 22:17
Does not yet work with ribasim-python.
The testmodels need to be present for the build process to work

I've also formatted, so the diff is slightly bigger than expected
Mypy doesn't like these dict defaults in config.py, since they are not the same type as the annotated type. Can't we somehow avoid copying the same defaults twice here?
@evetion
Copy link
Member

evetion commented Oct 26, 2023

I'll take over this branch in #731, thank you very much.

@visr visr closed this Nov 16, 2023
@visr visr deleted the pydantic branch November 16, 2023 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Start supporting pydantic v2
3 participants