Skip to content

Commit da3a557

Browse files
committed
more test
1 parent ea81c5e commit da3a557

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cf_xarray/tests/test_accessor.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,7 @@ def test_get_bounds_dim_name() -> None:
987987
ds.cf.get_bounds_dim_name("longitude")
988988

989989

990+
@requires_pyproj
990991
def test_grid_mappings():
991992
ds = rotds.copy(deep=False)
992993

@@ -1036,6 +1037,26 @@ def test_grid_mappings():
10361037
# grid_mapping_name
10371038
assert ds.cf["temp"].cf.grid_mapping_name == "rotated_latitude_longitude"
10381039

1040+
# Test .grid_mappings property with single grid mapping
1041+
grid_mappings = ds.cf.grid_mappings
1042+
assert len(grid_mappings) == 1
1043+
gm = grid_mappings[0]
1044+
assert gm.name == "rotated_latitude_longitude"
1045+
assert gm.array.name == "rotated_pole"
1046+
assert gm.array.shape == () # scalar variable
1047+
assert isinstance(gm.coordinates, tuple)
1048+
# Should have rlon and rlat detected from standard names
1049+
assert gm.coordinates == ("rlon", "rlat")
1050+
1051+
# Test .grid_mappings property on DataArray with propagated coords
1052+
da_grid_mappings = ds.cf["temp"].cf.grid_mappings
1053+
assert len(da_grid_mappings) == 1
1054+
da_gm = da_grid_mappings[0]
1055+
assert da_gm.name == "rotated_latitude_longitude"
1056+
assert da_gm.array.name == "rotated_pole"
1057+
# Should also detect rlon and rlat from standard names
1058+
assert da_gm.coordinates == ("rlon", "rlat")
1059+
10391060
# what if there are really 2 grid mappins?
10401061
ds["temp2"] = ds.temp
10411062
ds["temp2"].attrs["grid_mapping"] = "rotated_pole2"
@@ -1240,6 +1261,7 @@ def test_grid_mappings_coordinates_attribute():
12401261
)
12411262

12421263

1264+
@requires_pyproj
12431265
def test_bad_grid_mapping_attribute():
12441266
ds = rotds.copy(deep=False)
12451267
ds.temp.attrs["grid_mapping"] = "foo"
@@ -1255,6 +1277,10 @@ def test_bad_grid_mapping_attribute():
12551277
with pytest.warns(UserWarning):
12561278
ds.cf.get_associated_variable_names("temp", error=False)
12571279

1280+
# Test .grid_mappings property with bad grid mapping - should return empty tuple
1281+
grid_mappings = ds.cf.grid_mappings
1282+
assert grid_mappings == () # No valid grid mappings since 'foo' doesn't exist
1283+
12581284

12591285
def test_docstring() -> None:
12601286
assert "One of ('X'" in airds.cf.groupby.__doc__

0 commit comments

Comments
 (0)