Check if two attribute values are equivalent. Returns False if the comparison raises ValueError or TypeError. This handles cases like numpy arrays with ambiguous truth values and xarray Datasets which can't be directly converted to numpy arrays. Since equivalent() now handles non-b
(a: Any, b: Any)
| 615 | |
| 616 | |
| 617 | def equivalent_attrs(a: Any, b: Any) -> bool: |
| 618 | """Check if two attribute values are equivalent. |
| 619 | |
| 620 | Returns False if the comparison raises ValueError or TypeError. |
| 621 | This handles cases like numpy arrays with ambiguous truth values |
| 622 | and xarray Datasets which can't be directly converted to numpy arrays. |
| 623 | |
| 624 | Since equivalent() now handles non-boolean returns by returning False, |
| 625 | this wrapper mainly catches exceptions from comparisons that can't be |
| 626 | evaluated at all. |
| 627 | """ |
| 628 | try: |
| 629 | return equivalent(a, b) |
| 630 | except (ValueError, TypeError): |
| 631 | # These exceptions indicate the comparison is truly ambiguous |
| 632 | # (e.g., nested numpy arrays that would raise "ambiguous truth value") |
| 633 | return False |
| 634 | |
| 635 | |
| 636 | def merge_attrs(variable_attrs, combine_attrs, context=None): |
no test coverage detected
searching dependent graphs…