Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: be more careful about coercing unit-full containers to ndarray #21884

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 2 commits into from
Dec 10, 2021

Conversation

tacaswell
Copy link
Member

PR Summary

closes #21669

Tested manually locally via:

import matplotlib.pyplot as plt
import unyt as un

un.matplotlib_support.enable()
fig, ax = plt.subplots()

x = un.unyt_array([1, 2], "cm")
y = un.unyt_array([3, 4], "kg")
yerr = un.unyt_array([0.1, 0.2], "kg")
ax.errorbar(x, y, yerr=(yerr, yerr))

plt.show()

We do not currently have any tests of errorbar + units, in interest of getting 3.5.1 out with this fix and the colorbar fixes I move we merge this without a test and kick this particular technical debt can down the road as making sure we have good test coverage is in-scope for the NASA grant.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Dec 8, 2021
@tacaswell tacaswell added this to the v3.5.1 milestone Dec 8, 2021
jklymak
jklymak previously approved these changes Dec 8, 2021
@QuLogic
Copy link
Member

QuLogic commented Dec 9, 2021

cc @neutrinoceros

Copy link
Contributor

@neutrinoceros neutrinoceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm that this patch

  • fixes the addressed issue
  • fixes unyt's failing test
  • doesn't cause new test failures in unyt

thank you very much for this patch !

@jklymak jklymak dismissed their stale review December 9, 2021 09:56

Ooops, I guess this is broken somewhere...

@tacaswell
Copy link
Member Author

@efiring @dopplershift can you review this (pinging you based on timezone ;) ) so @QuLogic can get 3.5.1 out tonight?

I would also leave this to @QuLogic 's discretion to merge on one (his) review.

Copy link
Contributor

@dopplershift dopplershift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable. I think it would work for Pint, but honestly I haven't had need for errorbars, so I've never tested.

Copy link
Member

@efiring efiring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested clarification of docstring and comments need not delay merging.


If the units are carried on the values then casting to object
arrays preserves the units, but if the units are on the containers
this will not work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the docstring confusing, mixing the what and the why in a way that I can't sort out.
I suggest simply stating what it does under each case it handles.

"""

# we are here because we the container is not a numpy array, but it
# _is_ iterable (likely a list or a tuple but maybe something more
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But at this point you don't know it is iterable--you check it. If it is not iterable, you still wrap it in an object array.

# you can not directly pass data to the init of `np.ndarray`
if atype is np.ndarray:
return np.asarray(err, dtype=object)
# but you can for unyt and astropy uints
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

astropy "units", I presume

@QuLogic QuLogic merged commit 5bb1449 into matplotlib:main Dec 10, 2021
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Dec 10, 2021
QuLogic added a commit that referenced this pull request Dec 10, 2021
…884-on-v3.5.x

Backport PR #21884 on branch v3.5.x (FIX: be more careful about coercing unit-full containers to ndarray)
@tacaswell tacaswell deleted the fix_errorbar_units branch December 10, 2021 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: units and array ducktypes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Matplotlib 3.5 breaks unyt integration of error bars
6 participants