@@ -142,6 +142,40 @@ def test_do_not_overwrite_user_coordinates(self):
142
142
with pytest .raises (ValueError , match = r"'coordinates' found in both attrs" ):
143
143
conventions .encode_dataset_coordinates (orig )
144
144
145
+ def test_emit_coordinates_attribute_in_attrs (self ):
146
+ orig = Dataset (
147
+ {"a" : 1 , "b" : 1 },
148
+ coords = {"t" : np .array ("2004-11-01T00:00:00" , dtype = np .datetime64 )},
149
+ )
150
+
151
+ orig ["a" ].attrs ["coordinates" ] = None
152
+ enc , _ = conventions .encode_dataset_coordinates (orig )
153
+
154
+ # check coordinate attribute emitted for 'a'
155
+ assert "coordinates" not in enc ["a" ].attrs
156
+ assert "coordinates" not in enc ["a" ].encoding
157
+
158
+ # check coordinate attribute not emitted for 'b'
159
+ assert enc ["b" ].attrs .get ("coordinates" ) == "t"
160
+ assert "coordinates" not in enc ["b" ].encoding
161
+
162
+ def test_emit_coordinates_attribute_in_encoding (self ):
163
+ orig = Dataset (
164
+ {"a" : 1 , "b" : 1 },
165
+ coords = {"t" : np .array ("2004-11-01T00:00:00" , dtype = np .datetime64 )},
166
+ )
167
+
168
+ orig ["a" ].encoding ["coordinates" ] = None
169
+ enc , _ = conventions .encode_dataset_coordinates (orig )
170
+
171
+ # check coordinate attribute emitted for 'a'
172
+ assert "coordinates" not in enc ["a" ].attrs
173
+ assert "coordinates" not in enc ["a" ].encoding
174
+
175
+ # check coordinate attribute not emitted for 'b'
176
+ assert enc ["b" ].attrs .get ("coordinates" ) == "t"
177
+ assert "coordinates" not in enc ["b" ].encoding
178
+
145
179
@requires_dask
146
180
def test_string_object_warning (self ):
147
181
original = Variable (("x" ,), np .array (["foo" , "bar" ], dtype = object )).chunk ()
0 commit comments