Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New TestVariable.test_pad failure with pint 0.11 #3783

Closed
ArchangeGabriel opened this issue Feb 20, 2020 · 1 comment · Fixed by #3706
Closed

New TestVariable.test_pad failure with pint 0.11 #3783

ArchangeGabriel opened this issue Feb 20, 2020 · 1 comment · Fixed by #3706

Comments

@ArchangeGabriel
Copy link
Contributor

Since y-day, pint 0.11 was released and it results in a new test failure (in addition to the ones in #3778 and #3779):

____________________________ TestVariable.test_pad _____________________________

self = <xarray.tests.test_units.TestVariable object at 0x7f6bfd8c1b20>

    def test_pad(self):
        data = np.arange(4 * 3 * 2).reshape(4, 3, 2)
        v = self.cls(["x", "y", "z"], data)
    
        xr_args = [{"x": (2, 1)}, {"y": (0, 3)}, {"x": (3, 1), "z": (2, 0)}]
        np_args = [
            ((2, 1), (0, 0), (0, 0)),
            ((0, 0), (0, 3), (0, 0)),
            ((3, 1), (0, 0), (2, 0)),
        ]
        for xr_arg, np_arg in zip(xr_args, np_args):
            actual = v.pad_with_fill_value(**xr_arg)
            expected = np.pad(
                np.array(v.data.astype(float)),
                np_arg,
                mode="constant",
                constant_values=np.nan,
            )
            assert_array_equal(actual, expected)
            assert isinstance(actual._data, type(v._data))
    
        # for the boolean array, we pad False
        data = np.full_like(data, False, dtype=bool).reshape(4, 3, 2)
        v = self.cls(["x", "y", "z"], data)
        for xr_arg, np_arg in zip(xr_args, np_args):
>           actual = v.pad_with_fill_value(fill_value=False, **xr_arg)

xarray/tests/test_variable.py:813: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
xarray/core/variable.py:1210: in pad_with_fill_value
    array = np.pad(
<__array_function__ internals>:5: in pad
    ???
/usr/lib/python3.8/site-packages/pint/quantity.py:1543: in __array_function__
    return numpy_wrap("function", func, args, kwargs, types)
/usr/lib/python3.8/site-packages/pint/numpy_func.py:894: in numpy_wrap
    return handled[name](*args, **kwargs)
/usr/lib/python3.8/site-packages/pint/numpy_func.py:671: in _pad
    kwargs["constant_values"] = _recursive_convert(kwargs["constant_values"], units)
/usr/lib/python3.8/site-packages/pint/numpy_func.py:659: in _recursive_convert
    arg = unit._REGISTRY.Quantity(arg, unit)
/usr/lib/python3.8/site-packages/pint/quantity.py:200: in __new__
    inst._magnitude = _to_magnitude(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

value = False, force_ndarray = True, force_ndarray_like = False

    def _to_magnitude(value, force_ndarray=False, force_ndarray_like=False):
        if isinstance(value, (dict, bool)) or value is None:
>           raise TypeError("Invalid magnitude for Quantity: {0!r}".format(value))
E           TypeError: Invalid magnitude for Quantity: False

/usr/lib/python3.8/site-packages/pint/compat.py:49: TypeError
@keewis
Copy link
Collaborator

keewis commented Feb 21, 2020

this is going to be fixed in #3706 by overriding the test from VariableSubclassobjects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants