@@ -1383,24 +1383,46 @@ def test_roundtrip_timedelta64_nanosecond_precision_warning() -> None:
1383
1383
assert decoded_var .encoding ["dtype" ] == np .int64
1384
1384
1385
1385
1386
- def test_roundtrip_float_times () -> None :
1387
- # Regression test for GitHub issue #8271
1388
- fill_value = 20.0
1389
- times = [
1390
- np .datetime64 ("1970-01-01 00:00:00" , "ns" ),
1391
- np .datetime64 ("1970-01-01 06:00:00" , "ns" ),
1392
- np .datetime64 ("NaT" , "ns" ),
1393
- ]
1386
+ _TEST_ROUNDTRIP_FLOAT_TIMES_TESTS = {
1387
+ "GH-8271" : (
1388
+ 20.0 ,
1389
+ np .array (
1390
+ ["1970-01-01 00:00:00" , "1970-01-01 06:00:00" , "NaT" ],
1391
+ dtype = "datetime64[ns]" ,
1392
+ ),
1393
+ "days since 1960-01-01" ,
1394
+ np .array ([3653 , 3653.25 , 20.0 ]),
1395
+ ),
1396
+ "GH-9488-datetime64[ns]" : (
1397
+ 1.0e20 ,
1398
+ np .array (["2010-01-01 12:00:00" , "NaT" ], dtype = "datetime64[ns]" ),
1399
+ "seconds since 2010-01-01" ,
1400
+ np .array ([43200 , 1.0e20 ]),
1401
+ ),
1402
+ "GH-9488-timedelta64[ns]" : (
1403
+ 1.0e20 ,
1404
+ np .array ([1_000_000_000 , "NaT" ], dtype = "timedelta64[ns]" ),
1405
+ "seconds" ,
1406
+ np .array ([1.0 , 1.0e20 ]),
1407
+ ),
1408
+ }
1409
+
1394
1410
1395
- units = "days since 1960-01-01"
1411
+ @pytest .mark .parametrize (
1412
+ ("fill_value" , "times" , "units" , "encoded_values" ),
1413
+ _TEST_ROUNDTRIP_FLOAT_TIMES_TESTS .values (),
1414
+ ids = _TEST_ROUNDTRIP_FLOAT_TIMES_TESTS .keys (),
1415
+ )
1416
+ def test_roundtrip_float_times (fill_value , times , units , encoded_values ) -> None :
1417
+ # Regression test for GitHub issues #8271 and #9488
1396
1418
var = Variable (
1397
1419
["time" ],
1398
1420
times ,
1399
1421
encoding = dict (dtype = np .float64 , _FillValue = fill_value , units = units ),
1400
1422
)
1401
1423
1402
1424
encoded_var = conventions .encode_cf_variable (var )
1403
- np .testing .assert_array_equal (encoded_var , np . array ([ 3653 , 3653.25 , 20.0 ]) )
1425
+ np .testing .assert_array_equal (encoded_var , encoded_values )
1404
1426
assert encoded_var .attrs ["units" ] == units
1405
1427
assert encoded_var .attrs ["_FillValue" ] == fill_value
1406
1428
0 commit comments