Skip to content

Make TaggedValue in basic_units a sequence #19415

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

Merged
merged 1 commit into from
Feb 1, 2021

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Feb 1, 2021

This is needed to avoid a deprecation warning with numpy 1.20, and fixes the doc build.

See https://numpy.org/doc/stable/release/1.20.0-notes.html#arraylike-objects-which-do-not-define-len-and-getitem for more information. Essentially, __len__ and __getitem__ needed to be implemented for numpy to recognise the class as a sequence.

@jklymak jklymak mentioned this pull request Feb 1, 2021
@tacaswell tacaswell added this to the v3.4.0 milestone Feb 1, 2021
@tacaswell tacaswell merged commit 1233840 into matplotlib:master Feb 1, 2021
@dstansby dstansby deleted the array-example branch February 1, 2021 17:34
@QuLogic
Copy link
Member

QuLogic commented Feb 12, 2021

This fixed the example with NumPy 1.20, but broke it with older versions, specifically 1.18.1.

QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Feb 18, 2021
A unit is a scalar, not a length-1 array. Though `BasicUnit` implements
`__rmul__`, if multiplying by an array, the NumPy implementation will
call `__array__` instead. If the LHS is an array, everything is fine,
but if the LHS is a scalar, the previous code would incorrectly cause it
to be upcast to a 1D array. When `__getitem__` was added in matplotlib#19415,
`np.atleast_1d` started iterating each (now 1D, not scalar)
`TaggedValue`, seeing it was length 1, and made the x/y arrays into
(N, 1) instead of (N,).
tacaswell pushed a commit to QuLogic/matplotlib that referenced this pull request Mar 24, 2021
A unit is a scalar, not a length-1 array. Though `BasicUnit` implements
`__rmul__`, if multiplying by an array, the NumPy implementation will
call `__array__` instead. If the LHS is an array, everything is fine,
but if the LHS is a scalar, the previous code would incorrectly cause it
to be upcast to a 1D array. When `__getitem__` was added in matplotlib#19415,
`np.atleast_1d` started iterating each (now 1D, not scalar)
`TaggedValue`, seeing it was length 1, and made the x/y arrays into
(N, 1) instead of (N,).
QuLogic added a commit to QuLogic/matplotlib that referenced this pull request Mar 25, 2021
A unit is a scalar, not a length-1 array. Though `BasicUnit` implements
`__rmul__`, if multiplying by an array, the NumPy implementation will
call `__array__` instead. If the LHS is an array, everything is fine,
but if the LHS is a scalar, the previous code would incorrectly cause it
to be upcast to a 1D array. When `__getitem__` was added in matplotlib#19415,
`np.atleast_1d` started iterating each (now 1D, not scalar)
`TaggedValue`, seeing it was length 1, and made the x/y arrays into
(N, 1) instead of (N,).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants