@@ -212,7 +212,7 @@ def test_model_tides_multiplemodels(measured_tides_ds, models, output_format):
212212# Run tests for each unit, providing expected outputs
213213@pytest .mark .parametrize (
214214 "units, expected_range, expected_dtype" ,
215- [("m" , 10 , "float32" ), ("cm" , 1000 , "int16 " ), ("mm" , 10000 , "int16 " )],
215+ [("m" , 10 , "float32" ), ("cm" , 1000 , "Int16 " ), ("mm" , 10000 , "Int16 " )],
216216 ids = ["metres" , "centimetres" , "millimetres" ],
217217)
218218def test_model_tides_units (measured_tides_ds , units , expected_range , expected_dtype ):
@@ -232,6 +232,41 @@ def test_model_tides_units(measured_tides_ds, units, expected_range, expected_dt
232232 assert modelled_tides_df .tide_height .dtype == expected_dtype
233233
234234
235+ # Test for GitHub Issue #15: integer output units with NaN values
236+ # https://github.com/GeoscienceAustralia/eo-tides/issues/15
237+ @pytest .mark .parametrize ("units" , ["cm" , "mm" ], ids = ["centimetres" , "millimetres" ])
238+ def test_model_tides_units_with_nan (units ):
239+ """Test that integer output units handle NaN values correctly.
240+
241+ When cutoff is finite, points beyond the extrapolation distance
242+ receive NaN values. These should be converted to pd.NA in the
243+ nullable Int16 output, not raise an IntCastingNaNError.
244+ """
245+ # Use an inland point that will be beyond cutoff distance
246+ x_inland = [122.0 ]
247+ y_inland = [- 22.0 ]
248+ time = pd .date_range ("2020-01-01" , periods = 3 , freq = "6h" )
249+
250+ # This should not raise an error (was failing before fix)
251+ result = model_tides (
252+ x = x_inland ,
253+ y = y_inland ,
254+ time = time ,
255+ model = "EOT20" ,
256+ output_units = units ,
257+ cutoff = 10 , # 10km cutoff, inland point is beyond this
258+ )
259+
260+ # Verify dtype is nullable Int16
261+ assert result .tide_height .dtype == "Int16"
262+
263+ # Verify NaN values are represented as pd.NA
264+ assert result .tide_height .isna ().all ()
265+
266+ # Verify statistical operations work correctly (don't include NA)
267+ assert pd .isna (result .tide_height .mean ())
268+
269+
235270# Run test for each combination of mode, output format, and one or
236271# multiple tide models
237272@pytest .mark .parametrize (
0 commit comments