File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -2737,7 +2737,11 @@ def grid_mapping_name(self) -> str:
2737
2737
if not grid_mapping :
2738
2738
raise ValueError ("No 'grid_mapping' attribute present." )
2739
2739
2740
+ if grid_mapping not in da ._coords :
2741
+ raise ValueError (f"Grid Mapping variable { grid_mapping } not present." )
2742
+
2740
2743
grid_mapping_var = da [grid_mapping ]
2744
+
2741
2745
return grid_mapping_var .attrs ["grid_mapping_name" ]
2742
2746
2743
2747
def __getitem__ (self , key : Hashable | Iterable [Hashable ]) -> DataArray :
Original file line number Diff line number Diff line change @@ -1001,6 +1001,17 @@ def test_grid_mappings():
1001
1001
actual = ds .cf ["temp" ].cf ["rotated_latitude_longitude" ]
1002
1002
assert_identical (actual , expected )
1003
1003
1004
+ # not properly propagated if grid mapping variable not in coords
1005
+ with pytest .raises (
1006
+ ValueError , match = "Grid Mapping variable rotated_pole not present."
1007
+ ):
1008
+ ds .temp .cf .grid_mapping_name
1009
+
1010
+ # check for https://github.com/xarray-contrib/cf-xarray/issues/448
1011
+ expected = ds .rlon
1012
+ actual = rotds .temp .cf ["X" ]
1013
+ assert_identical (expected , actual )
1014
+
1004
1015
# Test repr
1005
1016
expected = """\
1006
1017
Grid Mappings: rotated_latitude_longitude: ['rotated_pole']"""
You can’t perform that action at this time.
0 commit comments