@@ -134,6 +134,38 @@ def test_repr():
134
134
# Flag DataArray
135
135
assert "CF Flag variable" in repr (basin .cf )
136
136
137
+ # "Temp" dataset
138
+ actual = airds ["air" ]._to_temp_dataset ().cf .__repr__ ()
139
+ expected = """\
140
+ Coordinates:
141
+ - CF Axes: * X: ['lon']
142
+ * Y: ['lat']
143
+ * T: ['time']
144
+ Z: n/a
145
+
146
+ - CF Coordinates: * longitude: ['lon']
147
+ * latitude: ['lat']
148
+ * time: ['time']
149
+ vertical: n/a
150
+
151
+ - Cell Measures: area: ['cell_area']
152
+ volume: n/a
153
+
154
+ - Standard Names: * latitude: ['lat']
155
+ * longitude: ['lon']
156
+ * time: ['time']
157
+
158
+ - Bounds: n/a
159
+
160
+ Data Variables:
161
+ - Cell Measures: area, volume: n/a
162
+
163
+ - Standard Names: air_temperature: [<this-array>]
164
+
165
+ - Bounds: n/a
166
+ """
167
+ assert actual == dedent (expected )
168
+
137
169
138
170
def test_axes ():
139
171
expected = dict (T = ["time" ], X = ["lon" ], Y = ["lat" ])
@@ -1078,7 +1110,7 @@ def test_drop_vars_and_set_coords(obj, attr):
1078
1110
# Cell measure
1079
1111
assert_identical (expected ("cell_area" ), actual ("area" ))
1080
1112
# Variables
1081
- if isinstance (obj , Dataset ):
1113
+ if isinstance (obj , Dataset ) and "air" in obj . data_vars :
1082
1114
assert_identical (expected ("air" ), actual ("air_temperature" ))
1083
1115
assert_identical (expected (obj .variables ), actual (obj .cf .keys ()))
1084
1116
@@ -1094,7 +1126,7 @@ def test_drop_sel_and_reset_coords(obj):
1094
1126
# Cell measure
1095
1127
assert_identical (obj .reset_coords ("cell_area" ), obj .cf .reset_coords ("area" ))
1096
1128
# Variable
1097
- if isinstance (obj , Dataset ):
1129
+ if isinstance (obj , Dataset ) and "air" in obj . data_vars :
1098
1130
assert_identical (
1099
1131
obj .reset_coords ("air" ), obj .cf .reset_coords ("air_temperature" )
1100
1132
)
@@ -1118,7 +1150,11 @@ def test_rename(obj):
1118
1150
cf_dict = {
1119
1151
"air_temperature" if isinstance (obj , Dataset ) else "longitude" : "renamed"
1120
1152
}
1121
- xr_dict = {"air" if isinstance (obj , Dataset ) else "lon" : "renamed" }
1153
+ xr_dict = {
1154
+ "air"
1155
+ if isinstance (obj , Dataset ) and "air" in obj .data_vars
1156
+ else "lon" : "renamed"
1157
+ }
1122
1158
assert_identical (obj .rename (xr_dict ), obj .cf .rename (cf_dict ))
1123
1159
assert_identical (obj .rename (** xr_dict ), obj .cf .rename (** cf_dict ))
1124
1160
0 commit comments