Skip to content

MDPDatastore raises KeyError for category="static" when no static data is present #732

Description

@AshNicolus

Description

MDPDatastore.get_dataarray's own docstring says: "'state' is the only required category, for other categories, the method will return None if the category is not found in the datastore." This matches the abstract base class contract (BaseDatastore.get_dataarray, base.py:234-238): "'forcing' and 'static' are optional (in which case the method should return None)."

But the implementation only special-cases "forcing":

if category not in self._ds and category == "forcing":
    warnings.warn("no forcing data found in datastore")
    return None

The identical pattern (only guarding "forcing", never "static") is copy-pasted across four methods in neural_lam/datastore/mdp.py: get_vars_units, get_vars_names, get_vars_long_names, and get_dataarray.

Failure scenario

An mllam-data-prep config that defines state and forcing inputs but no static output category (a legitimate configuration per the documented interface) raises an unhandled KeyError: "No variable named 'static'" from any of these four methods, instead of gracefully returning None/[] as the interface promises and as every caller (WeatherDataset, StepPredictor, etc.) expects.

Not covered by existing tests - tests/test_datastores.py only exercises example configs that always include all three categories.

Fix

Extend the guard in all four methods from category == "forcing" to category != "state", matching the documented "only state is required" contract, with a category-aware warning message.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions