Move from pandas to polars for local_ensemble.py - #13945
Conversation
6a36ef0 to
c2bad13
Compare
9743fd0 to
2091eae
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13945 +/- ##
==========================================
+ Coverage 91.85% 91.89% +0.03%
==========================================
Files 484 482 -2
Lines 33581 33544 -37
==========================================
- Hits 30847 30825 -22
+ Misses 2734 2719 -15
Flags with carried forward coverage won't be shown. Click here to find out more.
|
340b2f0 to
4cf340e
Compare
SAKavli
left a comment
There was a problem hiding this comment.
I have not finished reviewing, but will post the comments I have so far as I am joining a meeting now.
I can't put my finger on it yet, but I feel like there might be something to be done with the misfit changes, as we went from 12 lines to a lot more. We can look at this together later today!
|
Aha, when I come to the second commit, it makes sense why all the code in the first was added! |
SAKavli
left a comment
There was a problem hiding this comment.
We decided to redo the commit order and try to have a more clear separation of the removal of MeasuredData and the conversion from pandas to polars dataframes
213f9d6 to
fc47809
Compare
8ae1522 to
1151623
Compare
There was a problem hiding this comment.
Pull request overview
This PR completes the migration of misfit collection/measured-data plumbing around LocalEnsemble from pandas to polars, and updates downstream GUI/workflows/tests accordingly, including removing the previously exposed MeasuredData API.
Changes:
- Refactors
LocalEnsemble.load_all_misfit_data()to return apolars.DataFrameand inlines measured-data loading/validation intolocal_ensemble.py. - Updates GUI/workflow export paths to work with polars misfit tables (converting to pandas only where required for HDF output / existing pandas joins).
- Adjusts unit/UI tests and snapshots to reflect the new polars-based data structures and formatting.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/ert/unit_tests/test_misfit_collector.py | Updates snapshot generation and row-access expectations for polars misfit output. |
| tests/ert/unit_tests/snapshots/test_misfit_collector/test_misfit_collector/0/misfit_collector.csv | Refreshes snapshot values/formatting emitted by polars CSV writer. |
| tests/ert/unit_tests/scenarios/test_summary_response.py | Switches measured-data assertions from pandas/MeasuredData to polars _load_measured_data(). |
| tests/ert/unit_tests/gui/ertwidgets/test_ensemble_widget.py | Adds test ensuring GUI misfit retrieval returns a polars DataFrame. |
| tests/ert/unit_tests/data/test_integration_data.py | Reworks measured-data integration tests to use _load_measured_data() and polars columns. |
| tests/ert/unit_tests/data/snapshots/test_integration_data/test_all_measured_snapshot/0/snake_oil_measured_output.csv | Removes the old MeasuredData snapshot artifact. |
| tests/ert/ui_tests/gui/test_full_manual_update_workflow.py | Updates UI workflow test to use _load_measured_data() instead of MeasuredData. |
| src/ert/storage/local_ensemble.py | Implements polars misfit computation and moves measured-data loading/validation into LocalEnsemble. |
| src/ert/plugins/hook_implementations/workflows/export_misfit_data.py | Adapts misfit export workflow to polars misfit output, converting to pandas for HDF writing. |
| src/ert/plugins/hook_implementations/workflows/csv_export.py | Adapts CSV export workflow to polars misfit output, converting to pandas for joins. |
| src/ert/gui/tools/manage_experiments/ensemble_widget.py | Simplifies GUI misfit retrieval now that load_all_misfit_data() returns polars directly. |
| src/ert/data/_measured_data.py | Removes the pandas-based MeasuredData implementation. |
| src/ert/data/init.py | Removes ert.data export surface for MeasuredData. |
| src/ert/init.py | Removes top-level MeasuredData export from the public ert API. |
| import pytest | ||
|
|
||
|
|
||
| def test_misfit_collector(snake_oil_case_storage, snake_oil_default_storage, snapshot): |
| Returns: | ||
| DataFrame: A DataFrame containing the measured data for all | ||
| realizations in the ensemble. Each column corresponds to a key | ||
| in the measured data, and each row corresponds to a realization. | ||
| """ |
There was a problem hiding this comment.
Not changed in this PR, just moved
| def get_simulated_data(self, data: pd.DataFrame) -> pd.DataFrame: | ||
| """Dimension of data is (number of responses x number of realizations).""" | ||
| return data[~data.index.isin(["OBS", "STD"])] |
| from .config import ( | ||
| ForwardModelStepJSON, | ||
| ForwardModelStepPlugin, | ||
| ForwardModelStepValidationError, | ||
| ForwardModelStepWarning, | ||
| ForwardModelStepDocumentation, | ||
| ErtScript, | ||
| ErtScriptWorkflow, | ||
| WorkflowConfigs, | ||
| ) | ||
| from .data import MeasuredData | ||
| from .workflow_runner import WorkflowRunner |
There was a problem hiding this comment.
We don't believe this is used elsewhere
4106e50 to
fcc166d
Compare
a81fd0c to
dbca7ca
Compare
MeasuredData is only called from local_ensemble.py. In get_data we have calls back to local_ensemble.py. Moving the logic to local_ensemble.py prevents circular calls.
dbca7ca to
5ef9532
Compare
Issue
Resolves #13693
Approach
For moving from pandas to polars in local_ensemble.py there were multiple steps necessary:
First I introduced 2 tests to make sure the test coverage is good enough to move from pandas to polars without losing functionality.
In a next step I removed unused functionality from MeasuredData or functionality that was only used by tests and changed the tests accordingly.
Afterwards the logic from MeasuredData was moved to local_ensemble.py as MeasuredData was only called from local_ensemble.py and made calls back to local_ensemble.py.
In a final step all usage of pandas in local_ensemble.py was replaced by polars to improve consistency.
Remaining work to be found in #13954
(Screenshot of new behavior in GUI if applicable)
git rebase -i main --exec 'just rapid-tests')When applicable