@@ -244,6 +244,7 @@ def test_merge_attrs_drop_conflicts_non_bool_eq(self):
244
244
than raising an error.
245
245
"""
246
246
import numpy as np
247
+ import warnings
247
248
248
249
# Test with numpy arrays (which return arrays from ==)
249
250
arr1 = np .array ([1 , 2 , 3 ])
@@ -288,16 +289,21 @@ def __repr__(self):
288
289
ds5 = xr .Dataset (attrs = {"custom" : obj2 , "x" : 1 })
289
290
ds6 = xr .Dataset (attrs = {"custom" : obj3 , "y" : 2 })
290
291
291
- # Objects with same value (returning truthy array [True])
292
- actual = xr . merge ([ ds4 , ds5 ], combine_attrs = "drop_conflicts" )
293
- assert "custom" in actual . attrs
294
- assert actual . attrs [ "x" ] == 1
292
+ # Suppress DeprecationWarning from numpy < 2.0 about ambiguous truth values
293
+ # when our custom __eq__ returns arrays that are evaluated in boolean context
294
+ with warnings . catch_warnings ():
295
+ warnings . filterwarnings ( "ignore" , category = DeprecationWarning )
295
296
296
- # Objects with different values (returning falsy array [False])
297
- actual = xr .merge ([ds4 , ds6 ], combine_attrs = "drop_conflicts" )
298
- assert "custom" not in actual .attrs # Dropped due to conflict
299
- assert actual .attrs ["x" ] == 1
300
- assert actual .attrs ["y" ] == 2
297
+ # Objects with same value (returning truthy array [True])
298
+ actual = xr .merge ([ds4 , ds5 ], combine_attrs = "drop_conflicts" )
299
+ assert "custom" in actual .attrs
300
+ assert actual .attrs ["x" ] == 1
301
+
302
+ # Objects with different values (returning falsy array [False])
303
+ actual = xr .merge ([ds4 , ds6 ], combine_attrs = "drop_conflicts" )
304
+ assert "custom" not in actual .attrs # Dropped due to conflict
305
+ assert actual .attrs ["x" ] == 1
306
+ assert actual .attrs ["y" ] == 2
301
307
302
308
# Test edge case: object whose __eq__ returns empty array (ambiguous truth value)
303
309
class EmptyArrayEq :
@@ -317,8 +323,10 @@ def __repr__(self):
317
323
318
324
# With new behavior: ambiguous truth values are treated as non-equivalent
319
325
# So the attribute is dropped instead of raising an error
320
- actual = xr .merge ([ds7 , ds8 ], combine_attrs = "drop_conflicts" )
321
- assert "empty" not in actual .attrs # Dropped due to ambiguous comparison
326
+ with warnings .catch_warnings ():
327
+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
328
+ actual = xr .merge ([ds7 , ds8 ], combine_attrs = "drop_conflicts" )
329
+ assert "empty" not in actual .attrs # Dropped due to ambiguous comparison
322
330
323
331
# Test with object that returns multi-element array (also ambiguous)
324
332
class MultiArrayEq :
@@ -337,8 +345,10 @@ def __repr__(self):
337
345
ds10 = xr .Dataset (attrs = {"multi" : multi_obj2 })
338
346
339
347
# With new behavior: ambiguous arrays are treated as non-equivalent
340
- actual = xr .merge ([ds9 , ds10 ], combine_attrs = "drop_conflicts" )
341
- assert "multi" not in actual .attrs # Dropped due to ambiguous comparison
348
+ with warnings .catch_warnings ():
349
+ warnings .filterwarnings ("ignore" , category = DeprecationWarning )
350
+ actual = xr .merge ([ds9 , ds10 ], combine_attrs = "drop_conflicts" )
351
+ assert "multi" not in actual .attrs # Dropped due to ambiguous comparison
342
352
343
353
# Test with all-True multi-element array (unambiguous truthy)
344
354
class AllTrueArrayEq :
0 commit comments