Skip to content

Commit 0fad4c8

Browse files
committed
Suppress DeprecationWarning for ambiguous array truth values
The CI was failing because NumPy raises a DeprecationWarning before ValueError when evaluating ambiguous truth values. Since we're properly handling the ValueError, we suppress the warning in this specific context.
1 parent ed18a13 commit 0fad4c8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

xarray/structure/merge.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,16 @@ def merge_attrs(variable_attrs, combine_attrs, context=None):
650650
else:
651651
# Check if values are equivalent
652652
try:
653-
if equivalent(attrs[key], value):
654-
# Values are equivalent, keep the attribute
655-
filtered_result[key] = value
656-
# else: Values differ, drop the attribute (don't add to filtered_result)
653+
import warnings
654+
655+
# Suppress DeprecationWarning about ambiguous truth values
656+
# since we handle the resulting ValueError appropriately
657+
with warnings.catch_warnings():
658+
warnings.filterwarnings("ignore", category=DeprecationWarning)
659+
if equivalent(attrs[key], value):
660+
# Values are equivalent, keep the attribute
661+
filtered_result[key] = value
662+
# else: Values differ, drop the attribute (don't add to filtered_result)
657663
except ValueError:
658664
# Likely an ambiguous truth value from numpy array comparison
659665
# Treat as non-equivalent and drop the attribute

0 commit comments

Comments
 (0)