@@ -58,7 +58,7 @@ def test_builds_one_or_clause_per_target(patch_get_continuous):
5858 targets ,
5959 monitoring_location_id = "USGS-02238500" ,
6060 parameter_code = "00060" ,
61- window = "00:07:30 " ,
61+ window = "PT7M30S " ,
6262 )
6363 _ , kwargs = patch_get_continuous .call_args
6464 filter_expr = kwargs ["filter" ]
@@ -89,7 +89,7 @@ def test_tie_first_keeps_earlier(patch_get_continuous):
8989 targets ,
9090 monitoring_location_id = "USGS-02238500" ,
9191 on_tie = "first" ,
92- window = "00:07:30 " ,
92+ window = "PT7M30S " ,
9393 )
9494 assert len (result ) == 1
9595 assert result .iloc [0 ]["value" ] == 22.0
@@ -111,7 +111,7 @@ def test_tie_last_keeps_later(patch_get_continuous):
111111 targets ,
112112 monitoring_location_id = "USGS-02238500" ,
113113 on_tie = "last" ,
114- window = "00:07:30 " ,
114+ window = "PT7M30S " ,
115115 )
116116 assert result .iloc [0 ]["value" ] == 22.4
117117 assert result .iloc [0 ]["time" ] == pd .Timestamp ("2023-06-15T10:30:00Z" )
@@ -132,7 +132,7 @@ def test_tie_mean_averages_numeric_and_uses_target_time(patch_get_continuous):
132132 targets ,
133133 monitoring_location_id = "USGS-02238500" ,
134134 on_tie = "mean" ,
135- window = "00:07:30 " ,
135+ window = "PT7M30S " ,
136136 )
137137 assert result .iloc [0 ]["value" ] == pytest .approx (22.2 )
138138 # Time is set to the target since no real observation sits at the midpoint
@@ -232,23 +232,28 @@ def test_accepts_list_of_strings(patch_get_continuous):
232232 assert len (result ) == 1
233233
234234
235- def test_window_accepts_hhmmss_and_shorthand_equivalently (patch_get_continuous ):
236- """``window="00:07:30"`` and ``window="7min30s"`` are the same duration
237- as far as ``pandas.Timedelta`` is concerned, so the two forms must
238- produce identical CQL filters."""
235+ @pytest .mark .parametrize (
236+ "window" ,
237+ [
238+ "00:07:30" , # HH:MM:SS
239+ "7min30s" , # pandas shorthand
240+ "450s" , # seconds shorthand
241+ "PT7M30S" , # ISO 8601 duration
242+ pd .Timedelta (minutes = 7 , seconds = 30 ), # Timedelta object
243+ ],
244+ )
245+ def test_window_accepts_any_pandas_timedelta_form (patch_get_continuous , window ):
246+ """Every representation ``pandas.Timedelta`` parses must produce the
247+ same CQL filter. Documents the public contract: ``window`` is
248+ whatever ``pd.Timedelta(window)`` returns."""
239249 targets = pd .to_datetime (["2023-06-15T10:30:00Z" ], utc = True )
240250 patch_get_continuous .return_value = (_fake_df ([]), mock .Mock ())
241251
242- get_nearest_continuous (targets , monitoring_location_id = "USGS-1" , window = "00:07:30" )
243- filter_hhmmss = patch_get_continuous .call_args .kwargs ["filter" ]
244-
245- get_nearest_continuous (targets , monitoring_location_id = "USGS-1" , window = "7min30s" )
246- filter_shorthand = patch_get_continuous .call_args .kwargs ["filter" ]
247-
248- assert filter_hhmmss == filter_shorthand
249- # And the bounds should be 7:30 away from the target
250- assert "'2023-06-15T10:22:30Z'" in filter_hhmmss
251- assert "'2023-06-15T10:37:30Z'" in filter_hhmmss
252+ get_nearest_continuous (targets , monitoring_location_id = "USGS-1" , window = window )
253+ filter_expr = patch_get_continuous .call_args .kwargs ["filter" ]
254+ # Bounds are 7:30 away from the target regardless of input spelling
255+ assert "'2023-06-15T10:22:30Z'" in filter_expr
256+ assert "'2023-06-15T10:37:30Z'" in filter_expr
252257
253258
254259def test_forwards_kwargs_to_get_continuous (patch_get_continuous ):
0 commit comments