pydata / xarray

N-D labeled arrays and datasets in Python
https://xarray.dev
Apache License 2.0
3.49k stars 1.04k forks source link

properly diff objects with arrays as attributes on variables #9169

Closed keewis closed 2 days ago

keewis commented 1 week ago
dcherian commented 1 week ago

Oops, the property test did find something. We can skip these in the test if you want though, they seem pretty edge-casey

first = {'': array([False, False])}, second = {'': array([False, False])}

    def equivalent(first: T, second: T) -> bool:
        """Compare two objects for equivalence (identity or equality), using
        array_equiv if either object is an ndarray. If both objects are lists,
        equivalent is sequentially called on all the elements.
        """
        # TODO: refactor to avoid circular import
        from xarray.core import duck_array_ops

        if first is second:
            return True
        if isinstance(first, np.ndarray) or isinstance(second, np.ndarray):
            return duck_array_ops.array_equiv(first, second)
        if isinstance(first, list) or isinstance(second, list):
            return list_equiv(first, second)
>       return (first == second) or (pd.isnull(first) and pd.isnull(second))
E       ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
keewis commented 1 week ago

true. To fix that, we'd have to support recursive attrs, which feels like a bit too much effort. If anything, I'd raise a ValueError stating that assert_* don't support those.