@@ -177,6 +177,48 @@ def test_missing_categorical():
177
177
a = a .isel (expressions = 0 )
178
178
assert all (a == np .asarray ([1 , 0 , 1 , 1 , 1 , 1 ]))
179
179
180
+ expr = "df.TourMode2 != 'BAD'"
181
+ with pytest .warns (UserWarning ):
182
+ f8 = tree .setup_flow ({expr : expr }, with_root_node_name = "df" )
183
+ a = f8 .load_dataarray (dtype = np .int8 )
184
+ a = a .isel (expressions = 0 )
185
+ assert all (a == np .asarray ([1 , 1 , 1 , 1 , 1 , 1 ]))
186
+
187
+ expr = "'BAD' != df.TourMode2"
188
+ with pytest .warns (UserWarning ):
189
+ f9 = tree .setup_flow ({expr : expr }, with_root_node_name = "df" )
190
+ a = f9 .load_dataarray (dtype = np .int8 )
191
+ a = a .isel (expressions = 0 )
192
+ assert all (a == np .asarray ([1 , 1 , 1 , 1 , 1 , 1 ]))
193
+
194
+ expr = "(df.TourMode2 == 'BAD') * 2"
195
+ with pytest .warns (UserWarning ):
196
+ fA = tree .setup_flow ({expr : expr }, with_root_node_name = "df" )
197
+ a = fA .load_dataarray (dtype = np .int8 )
198
+ a = a .isel (expressions = 0 )
199
+ assert all (a == np .asarray ([0 , 0 , 0 , 0 , 0 , 0 ]))
200
+
201
+ expr = "(df.TourMode2 == 'BAD') * 2.2"
202
+ with pytest .warns (UserWarning ):
203
+ fB = tree .setup_flow ({expr : expr }, with_root_node_name = "df" )
204
+ a = fB .load_dataarray (dtype = np .int8 )
205
+ a = a .isel (expressions = 0 )
206
+ assert all (a == np .asarray ([0 , 0 , 0 , 0 , 0 , 0 ]))
207
+
208
+ expr = "np.exp(df.TourMode2 == 'BAD') * 2.2"
209
+ with pytest .warns (UserWarning ):
210
+ fC = tree .setup_flow ({expr : expr }, with_root_node_name = "df" )
211
+ a = fC .load_dataarray (dtype = np .float32 )
212
+ a = a .isel (expressions = 0 )
213
+ assert all (a == np .asarray ([2.2 , 2.2 , 2.2 , 2.2 , 2.2 , 2.2 ], dtype = np .float32 ))
214
+
215
+ expr = "(df.TourMode2 != 'BAD') * 2"
216
+ with pytest .warns (UserWarning ):
217
+ fD = tree .setup_flow ({expr : expr }, with_root_node_name = "df" )
218
+ a = fD .load_dataarray (dtype = np .int8 )
219
+ a = a .isel (expressions = 0 )
220
+ assert all (a == np .asarray ([2 , 2 , 2 , 2 , 2 , 2 ]))
221
+
180
222
181
223
def test_categorical_indexing (tours_dataset : xr .Dataset , skims_dataset : xr .Dataset ):
182
224
tree = sharrow .DataTree (tours = tours_dataset )
0 commit comments