Skip to content

Implement diff on Models. - #2080

Merged
evetion merged 4 commits into
mainfrom
feat/model-compare
Feb 20, 2025
Merged

Implement diff on Models.#2080
evetion merged 4 commits into
mainfrom
feat/model-compare

Conversation

@evetion

@evetion evetion commented Feb 20, 2025

Copy link
Copy Markdown
Member

Fixes Deltares/Ribasim-NL#229

Implements diff on Models and its children. Either gives back None when models are equal, or a (nested) dict with the differences. When the differences are not a DataFrame (like the toml config), the dict has self and other as key. For DataFrames we return a dict with diff as key, and a datacompy Comparison object.

>>> nbasic == basic
False
>>> x = nbasic.diff(basic)
{'basin': {'node': {'diff': <datacompy.core.Compare object at 0x16e5a45c0>},
           'static': {'diff': <datacompy.core.Compare object at 0x16eb90080>}},
 'solver': {'saveat': {'other': 86400.0, 'self': 0.0}}}
>>> x["basin"]["static"]["diff"].report()
DataComPy Comparison
--------------------

DataFrame Summary
-----------------

  DataFrame  Columns  Rows
0      self        5     5
1     other        5     4

Column Summary
--------------

Number of columns in common: 5
Number of columns in self but not in other: 0 []
Number of columns in other but not in self: 0 []

Row Summary
-----------

Matched on: index
Any duplicates on match values: No
Absolute Tolerance: 0
Relative Tolerance: 0
Number of rows in common: 4
Number of rows in self but not in other: 1
Number of rows in other but not in self: 0

Number of rows with some compared columns unequal: 0
Number of rows with all compared columns equal: 4

Column Comparison
-----------------

Number of columns compared with some values unequal: 0
Number of columns compared with all values equal: 5
Total number of values which compare unequal: 0

Sample Rows Only in self (First 10 Columns)
-------------------------------------------

     node_id  drainage  potential_evaporation  infiltration  precipitation
fid
4         18      <NA>                   <NA>          <NA>            4.0

I've tried deepdiff and other diff plugins, but none seem to combine nested Pydantic models and DataFrames. Comparing DataFrames using the built-in compare only works for identical shapes (limiting it's use).

  • Ignore meta_ keys in DataFrames

@evetion
evetion requested a review from visr February 20, 2025 10:09
@evetion
evetion marked this pull request as ready for review February 20, 2025 12:39

@visr visr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff looks good!

@evetion
evetion merged commit 30dfed7 into main Feb 20, 2025
@evetion
evetion deleted the feat/model-compare branch February 20, 2025 13:36
@visr visr mentioned this pull request Feb 20, 2025
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.

Modellen vergelijken

2 participants