Skip to content

Port to the plain-string trait profiles from mlwp-data-specs#42 #51

Open

Description

@mpvginde

Problem

mlwp-tools/mlwp-data-specs#42 replaced the Space, Time and Uncertainty enums with classes whose members are plain strings. Time.FORECAST is now the str "forecast". The classes can't be called, and their members have no .value, so mxalign fails wherever it does either.

refactor/alignment (1eb4d7f) with mlwp-data-specs at Tests
29746f1, just before mlwp-tools/mlwp-data-specs#42 100 passed
ca15388, with that PR 65 failed, 35 passed

The failures come from Time() takes no arguments, Space() takes no arguments and 'str' object has no attribute 'value'.

CI doesn't show this because [tool.uv.sources] pins mlwp-data-specs to 059f382. It appears in a dev environment with a local mlwp-data-specs checkout on main, and it will appear at the next pin bump.

main is affected too, but less: its 3 tests pass because they don't reach update_*_trait, which still calls new_trait.value.

What needs changing

On refactor/alignment:

Location Now Change
src/mxalign/accessor/mx.py:75 Space(self._trait(SPACE_TRAIT_ATTR)) Return the attribute value, after checking it
src/mxalign/accessor/mx.py:91 Time(self._trait(TIME_TRAIT_ATTR)) Same
src/mxalign/alignment/time.py:307 Time.OBSERVATION.value Time.OBSERVATION
src/mxalign/alignment/time.py:382 Time.FORECAST.value Time.FORECAST
src/mxalign/utils/traits.py:46, 69, 92 new_trait.value new_trait

On main, the traits.py lines are 24, 30 and 36.

Space(value) and Time(value) also raised ValueError on an unknown value, so the accessors need an explicit check to keep that, for example:

value = self._trait(TIME_TRAIT_ATTR)
if value not in Time:
    raise ValueError(f"Invalid '{TIME_TRAIT_ATTR}' attribute: {value!r}")
return value

The _space and _time return annotations and docstrings become str.

Notes

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