Fix MDPDatastore raising KeyError for category="static" when absent - #733
AshNicolus wants to merge 2 commits into
Conversation
|
Thanks @AshNicolus, this is the right fix and overlaps with #231 (fixes #125), where I proposed the same change across all four accessors in varunsiravuri#2 but it never landed. Are you still interested in getting this merged once v0.7.0 is released? If so I would rebase on main and replace the object.new test with a proper state-only datastore config like the one in #231. And plese restore the full PR template |
|
Yes, still interested in merging after v0.7.0. I'll rebase on main, replace the test with a proper state-only datastore config, and restore the full PR template. |
get_dataarray's own docstring (and the abstract base class contract) say only "state" is required, with "forcing" and "static" both optional and returning None/[] when missing. The guard in get_vars_units, get_vars_names, get_vars_long_names and get_dataarray only special-cased "forcing", so a static-less mllam-data-prep config raised an unhandled KeyError instead. Extend the guard to category != "state", matching the documented contract, with a category-aware warning message. Closes mllam#732
30280da to
8a4ac89
Compare
8a4ac89 to
889200b
Compare
|
Rebased on latest main and updated the test comment. Ready for merge after v0.7.0. |
|
@AshNicolus you really need to fix the PR template in all your open PR descriptions. we need to the full template with all checkboxes to merge into main |
Describe your changes
MDPDatastore.get_dataarray's own docstring says "'state' is the only required category, for other categories, the method will returnNoneif the category is not found in the datastore" - matching the abstract base class contract (BaseDatastore.get_dataarray: "'forcing' and 'static' are optional (in which case the method should returnNone)").But the implementation only special-cased
"forcing":This exact pattern was copy-pasted across four methods (
get_vars_units,get_vars_names,get_vars_long_names,get_dataarray), never handling"static". Anmllam-data-prepconfig withstate+forcingbut nostaticoutput category - a legitimate configuration per the documented interface - raised an unhandledKeyError: "No variable named 'static'"instead of gracefully returningNone/[].Fix: extend the guard from
category == "forcing"tocategory != "state"in all four places, matching the documented "only state is required" contract, with a category-aware warning message so it still says the right thing for either missing category.Added a regression test (bypassing the full
mllam-data-prepmachinery with a synthetic_ds, same pattern as other lightweight datastore unit tests) - verified it fails with the originalKeyErrorbefore the fix and passes after. Fulltests/test_datastores.pysuite (55 tests) passes with real network access.Issue Link
closes #732
Type of change
Checklist before requesting a review
pullwith--rebaseoption if possible).