@@ -27,6 +27,28 @@ def setup(self, tmp_path):
27
27
dir .mkdir ()
28
28
self .file_path = f"{ dir } /file.nc"
29
29
30
+ def test_raises_warning_if_decode_times_but_no_time_coords_found (self , caplog ):
31
+ ds = generate_dataset (decode_times = False , cf_compliant = True , has_bounds = True )
32
+ ds = ds .drop_dims ("time" )
33
+ ds .to_netcdf (self .file_path )
34
+
35
+ result = open_dataset (self .file_path )
36
+ expected = generate_dataset (
37
+ decode_times = False ,
38
+ cf_compliant = True ,
39
+ has_bounds = True ,
40
+ )
41
+ expected = expected .drop_dims ("time" )
42
+
43
+ assert result .identical (expected )
44
+ assert (
45
+ "No time coordinates were found in this dataset to decode. Make sure time "
46
+ "coordinates exist and their CF 'axis' or 'standard_name' attribute is set "
47
+ "(e.g., ds['time'].attrs['axis'] = 'T' or "
48
+ "ds['time'].attrs['standard_name'] = 'time'). Afterwards, try decoding "
49
+ "with `decode_time()` again."
50
+ ) in caplog .text
51
+
30
52
def test_skip_decoding_time_explicitly (self ):
31
53
ds = generate_dataset (decode_times = False , cf_compliant = True , has_bounds = True )
32
54
ds .to_netcdf (self .file_path )
@@ -567,6 +589,28 @@ def setUp(self, tmp_path):
567
589
self .file_path1 = f"{ dir } /file1.nc"
568
590
self .file_path2 = f"{ dir } /file2.nc"
569
591
592
+ def test_raises_warning_if_decode_times_but_no_time_coords_found (self , caplog ):
593
+ ds = generate_dataset (decode_times = False , cf_compliant = True , has_bounds = True )
594
+ ds = ds .drop_dims ("time" )
595
+ ds .to_netcdf (self .file_path1 )
596
+
597
+ result = open_mfdataset (self .file_path1 )
598
+ expected = generate_dataset (
599
+ decode_times = False ,
600
+ cf_compliant = True ,
601
+ has_bounds = True ,
602
+ )
603
+ expected = expected .drop_dims ("time" )
604
+
605
+ assert result .identical (expected )
606
+ assert (
607
+ "No time coordinates were found in this dataset to decode. Make sure time "
608
+ "coordinates exist and their CF 'axis' or 'standard_name' attribute is set "
609
+ "(e.g., ds['time'].attrs['axis'] = 'T' or "
610
+ "ds['time'].attrs['standard_name'] = 'time'). Afterwards, try decoding "
611
+ "with `decode_time()` again."
612
+ ) in caplog .text
613
+
570
614
def test_skip_decoding_times_explicitly (self ):
571
615
ds1 = generate_dataset (decode_times = False , cf_compliant = False , has_bounds = True )
572
616
ds1 .to_netcdf (self .file_path1 )
0 commit comments