Skip to content

Conversation

@ValentinGebhart
Copy link
Collaborator

Changes proposed in this PR:

  • add select method that first select upon member and lead_time argurments, encodes this in event_id, and then call Hazard.select with the new event_id
  • expand tests

This PR fixes #1157

PR Author Checklist

PR Reviewer Checklist

if lead_time is not None
else np.full_like(self.lead_time, True, dtype=bool)
)
mask_event_id = np.asarray(self.event_id)[(mask_member & mask_lead_time)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is probably not a mask anymore, but the event id you select right? Just to be sure this is the wanted behaviour (which I think it is).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'll adapt the naming!


assert haz_fc_sel.centroids == haz_fc.centroids

def test_derived_select(self, haz_fc, lead_time, member, haz_kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would here also use the @pytest.mark.parametrize . This makes the eventual error messages much clearer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I'm a bit confused about the parameterize. Above it seems to be for running the test multiple times with a different select variable. Here we are also testing on different combinations of select variables and their interactions, so I'm not sure how to make use of the parametrize here..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way is then to make one test/function for each combination.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One function for separate leadtime/member selection, one function for the combined selections, one function for "emtpy" selections (as discussed below)

)
haz_fc_select = haz_fc2.select(event_id=[1, 2, 4], member=[0])
npt.assert_array_equal(haz_fc_select.event_id, [1, 2, 4])
npt.assert_array_equal(haz_fc_select.member, [0, 0, 0])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@peanutfun Should we add a test for "no match"?
Something like
haz_fc_empty = haz_fc.select(event_names = haz_fc.event_name[:2], member=member[-2:])
will raise
IndexError: arrays used as indices must be of integer (or boolean) type
that we could test for. Not sure if this is behaviour that we want, though, I would rather expect an empty HazardForecast. But it is the same behaviour as Hazard.select()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct, there should be a test. But we should not go further than the functionality of Hazard.select. If that's the error from the base class, I'm fine with it being raised here, too.

@peanutfun peanutfun merged commit 302be63 into forecast-class Dec 10, 2025
10 of 11 checks passed
@ValentinGebhart ValentinGebhart deleted the add_sel_to_haz_and_imp_forecast branch December 10, 2025 11:02
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.

5 participants