Skip to content

Raise a clear error when a model result has no data at the observation - #722

Closed
syahra712 wants to merge 1 commit into
DHI:mainfrom
syahra712:fix-506-empty-model-result-error
Closed

syahra712 wants to merge 1 commit into
DHI:mainfrom
syahra712:fix-506-empty-model-result-error

Conversation

@syahra712

Copy link
Copy Markdown

Fixes #506

As scoped in #506 (comment), this replaces the bare assert with a descriptive error rather than changing matching behaviour.

When extraction gives an empty model result (the observation is outside the domain, or the location is dry), match() used to fail inside _get_global_start_end with:

AssertionError: All datetime indices must be non-empty

It now raises:

ValueError: Model result 'Model' has no data at observation 'Station'. Check that the observation is inside the model domain and that the model has valid values there (e.g. the location is not dry).

The check is a new _check_model_results_not_empty, which runs next to _check_timezone_compatibility in _match_space_time and follows the same pattern, so the message can name both the model result and the observation. The assert in _get_global_start_end is removed, because that function is now only reached with non-empty indices. Behaviour changes only for inputs that already failed: they now raise ValueError instead of AssertionError.

Test: I added test_match_raises_clear_error_when_model_result_is_empty next to the timezone test. It matches a PointObservation against an empty PointModelResult and checks the error names both of them. It fails on main and passes here. Apart from this new test, tests/test_match.py, tests/test_comparer.py and tests/test_simple_compare.py give the same results before and after the change. ruff check, ruff format --check and mypy on matching.py pass.

match() failed with a bare AssertionError from _get_global_start_end
when extraction gave an empty model result (e.g. the observation is
outside the domain or the location is dry). Check for this up front,
alongside the timezone check, and raise a ValueError that names the
model result and the observation.

Fixes DHI#506
@ecomodeller

Copy link
Copy Markdown
Member

Thanks for taking the time to look into this. We're handling this issue internally, so I'm closing this PR.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems with match() (flooding/drying)

2 participants