Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ if report.has_fails():
raise SystemExit("Dataset validation failed")
```

The API also accepts the requested alias spelling:

```python
report = validate_dataset(ds, time="forecast", space="grid", uncertaity="deterministic")
```

## Development

Run tests:
Expand Down
15 changes: 6 additions & 9 deletions src/mlwp_data_specs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@ def validate_dataset(
time: Time | str | None = None,
space: Space | str | None = None,
uncertainty: Uncertainty | str | None = None,
uncertaity: Uncertainty | str | None = None,
) -> ValidationReport:
"""Validate a dataset against selected trait specifications.

If a trait is not explicitly provided as an argument, this function
will attempt to resolve it from the dataset's attributes (e.g.,
``mlwp_time_trait``, ``mlwp_space_trait``, ``mlwp_uncertainty_trait``).
If both are provided and differ, the argument takes precedence.

Parameters
----------
ds : xr.Dataset
Expand All @@ -142,8 +146,6 @@ def validate_dataset(
uncertainty : Uncertainty | str | None, optional
Uncertainty trait profile (for example ``"deterministic"``,
``"ensemble"``, or ``"quantile"``).
uncertaity : Uncertainty | str | None, optional
Backward-compatible alias for ``uncertainty`` (spelling preserved).

Returns
-------
Expand All @@ -155,14 +157,9 @@ def validate_dataset(
ValueError
Raised when no traits are selected or when invalid trait values are provided.
"""
if uncertainty is not None and uncertaity is not None:
raise ValueError("Provide only one of 'uncertainty' or 'uncertaity', not both")

uncertainty_value = uncertainty if uncertainty is not None else uncertaity

time_trait = _resolve_trait(ds, time, Time)
space_trait = _resolve_trait(ds, space, Space)
uncertainty_trait = _resolve_trait(ds, uncertainty_value, Uncertainty)
uncertainty_trait = _resolve_trait(ds, uncertainty, Uncertainty)

if not any([time_trait, space_trait, uncertainty_trait]):
raise ValueError("At least one trait must be selected")
Expand Down
8 changes: 0 additions & 8 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ def test_validate_dataset_accepts_string_traits() -> None:
assert not report.has_fails()


def test_validate_dataset_supports_uncertaity_alias() -> None:
"""API accepts the spelled-as-requested uncertainty alias argument."""
report = validate_dataset(
_forecast_grid_ds(), time="forecast", space="grid", uncertaity="deterministic"
)
assert not report.has_fails()


def test_validate_dataset_requires_trait() -> None:
"""API raises when no traits are selected."""
with pytest.raises(ValueError, match="At least one trait"):
Expand Down
Loading