Skip to content

Fix Comparer.sel() with date string when some comparers have no temporal overlap - #669

Draft
ryan-kipawa with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-time-arg-errors-comparercollection-sel
Draft

Fix Comparer.sel() with date string when some comparers have no temporal overlap#669
ryan-kipawa with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-time-arg-errors-comparercollection-sel

Conversation

CopilotAI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

ComparerCollection.sel(time='2022-01-03') raised an error instead of silently dropping comparers with no data on that date.

Two bugs in Comparer.sel() when time is a non-slice string:

  • KeyError — when the comparer has no data for the selected date, xarray raises instead of returning empty
  • ValueError: IndexVariable objects must be 1-dimensional — when daily data has an exact timestamp match, ds.sel(time='2019-01-03') returns a 0D scalar dataset, which the Comparer constructor rejects

Fix (_comparison.py):

  • Wrap d.sel(time=time) in try/except KeyError → empty selection on miss
  • After successful selection, call d.expand_dims("time") when result is 0D (exact match on daily data)
  • Skip raw_mod_data nearest-time lookup when matched data is empty
# Before: raises KeyError if Koege has no data on Jan 3cc.sel(time="2022-01-03")
# After: Koege excluded from result, other comparers returnedcc.sel(time="2022-01-03") # works, drops comparers with no data on that date

Tests (test_comparercollection.py): replaced the # TODO: FAILS commented-out test with two correct tests covering both the overlap and no-overlap cases.

When calling Comparer.sel(time='2022-01-03') (non-slice string):
- If no data exists for that date, xarray raises KeyError → now returns empty comparer
- If exact daily timestamp exists, xarray returns 0D dataset causing 'IndexVariable
must be 1-dimensional' → now expanded back to 1D with expand_dims
Also replaces the TODO: FAILS commented-out test with two correct failing tests
that now pass after the fix.
CopilotAI changed the title [WIP] Fix time arg errors in ComparerCollection.sel() methodFix Comparer.sel() with date string when some comparers have no temporal overlapJun 10, 2026
CopilotAI requested a review from ryan-kipawaJune 10, 2026 09:53
Sign up for freeto 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.

ComparerCollection.sel(), time arg errors when selecting a month where some comparers have no temporal overlap

2 participants

@ryan-kipawa