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

Numpy 1.20.0 causes problems for MaskedArrayWithLimits #161

Closed
weaverba137 opened this issue Feb 3, 2021 · 1 comment · Fixed by #162
Closed

Numpy 1.20.0 causes problems for MaskedArrayWithLimits #161

weaverba137 opened this issue Feb 3, 2021 · 1 comment · Fixed by #162
Assignees
Labels

Comments

@weaverba137
Copy link
Member

Traceback from a recent test with Numpy 1.20.0:

______________________ TestPlots.test_masked_array_limits ______________________

self = <desiutil.test.test_plots.TestPlots testMethod=test_masked_array_limits>

    def test_masked_array_limits(self):
        """Test MaskedArrayWithLimits
        """
        from ..plots import MaskedArrayWithLimits
        data = np.arange(5.)
        mask = data < 3
>       ma = MaskedArrayWithLimits(data, mask, vmin=1.0, vmax=4.0)

py/desiutil/test/test_plots.py:46: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'desiutil.plots.MaskedArrayWithLimits'>
args = (array([0., 1., 2., 3., 4.]), array([ True,  True,  True, False, False]))
kwargs = {'vmax': 4.0, 'vmin': 1.0}

    def __new__(cls, *args, **kwargs):
>       obj = super(MaskedArrayWithLimits, cls).__new__(cls, *args, **kwargs)
E       TypeError: __new__() got an unexpected keyword argument 'vmin'

py/desiutil/plots.py:157: TypeError

I suspect that the extra attributes could be added after the call to __new__().

@weaverba137 weaverba137 added the bug label Feb 3, 2021
@weaverba137 weaverba137 self-assigned this Feb 3, 2021
@weaverba137
Copy link
Member Author

After testing some testing, this seems to work:

        try:
            obj = super(MaskedArrayWithLimits, cls).__new__(cls, *args, **kwargs)
        except TypeError:
            # Numpy >= 1.20.0
            trimmed_kwargs = kwargs.copy()
            if 'vmin' in trimmed_kwargs:
                del trimmed_kwargs['vmin']
            if 'vmax' in trimmed_kwargs:
                del trimmed_kwargs['vmax']
            obj = super(MaskedArrayWithLimits, cls).__new__(cls, *args, **trimmed_kwargs)

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

Successfully merging a pull request may close this issue.

1 participant