@@ -50,3 +50,46 @@ def test_forecast_init():
5050 forecast = Forecast (lead_time = lead_times_seconds , member = [1 , 2 , 3 ])
5151 npt .assert_array_equal (forecast .lead_time , lead_times_seconds , strict = True )
5252 assert forecast .lead_time .dtype == np .dtype ("timedelta64[ns]" )
53+
54+
55+ def test_idx_member ():
56+ """Test idx_member method of Forecast class."""
57+ forecast = Forecast (member = np .array ([1 , 2 , 3 , 4 ]))
58+
59+ idx = forecast .idx_member (1 )
60+ npt .assert_array_equal (idx , np .array ([True , False , False , False ]), strict = True )
61+
62+ idx = forecast .idx_member (np .array ([2 , 4 ]))
63+ npt .assert_array_equal (idx , np .array ([False , True , False , True ]), strict = True )
64+
65+ idx = forecast .idx_member ([2 , 4 ])
66+ npt .assert_array_equal (idx , np .array ([False , True , False , True ]), strict = True )
67+
68+ idx = forecast .idx_member (None )
69+ npt .assert_array_equal (idx , np .array ([False , False , False , False ]), strict = True )
70+
71+ # Try once with inconsitent types
72+ forecast = Forecast (member = np .array (["1" , - 2 , np .nan ]))
73+ npt .assert_array_equal (
74+ forecast .idx_member ([np .nan , "1" ]), np .array ([True , False , True ]), strict = True
75+ )
76+
77+
78+ def test_idx_lead_time ():
79+ """Test idx_lead_time method of Forecast class."""
80+ forecast = Forecast (
81+ lead_time = pd .timedelta_range (start = "1 day" , periods = 4 ).to_numpy ()
82+ )
83+
84+ idx = forecast .idx_lead_time (
85+ pd .timedelta_range (start = "1 day" , periods = 4 ).to_numpy ()[::2 ]
86+ )
87+ npt .assert_array_equal (idx , np .array ([True , False , True , False ]), strict = True )
88+
89+ idx = forecast .idx_lead_time (
90+ pd .timedelta_range (start = "1 day" , periods = 4 ).to_numpy ()[0 ]
91+ )
92+ npt .assert_array_equal (idx , np .array ([True , False , False , False ]), strict = True )
93+
94+ idx = forecast .idx_lead_time (None )
95+ npt .assert_array_equal (idx , np .array ([False , False , False , False ]), strict = True )
0 commit comments