-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix: restore make_axes to accept a tuple of axes #24408
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
Fix: restore make_axes to accept a tuple of axes #24408
Conversation
ee2ee26
to
3eba834
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping @matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
Hi @PiotrStrzelczykX, thanks for the PR! Can you please provide a little more context, like a link to the PR where this memory leak went fix was implemented or to an open issue, if it exists, discussing the problem you are trying to solve here? |
Hello @story645, I added link to PR which changed this behavior.
and prepared this fix. |
Please add a test and maybe also include your test code in the issue. If we broke something once it is because there is no test. |
Actually I guess we should discuss if we want to accept a tuple. That may have worked before, but it wasn't documented, or particularly intended. |
General typing advice is to be open about what you accept and strict about what you output.
Perhaps we should be testing/documenting as |
Sure that sounds reasonable. However, being permissive is tricky practically when you are trying to write type checks etc, and for testing, since we can't check everything that quacks to make sure we don't break it. |
I suspect the right check here is to see if it is an iterable and special case if it is an array. Maybe right path is something like
thus we come out of this block it is definitly a list, we special case the np.array case (which might break with some future numpy-clone), and we let Python do the coerces to list for us. |
@tacaswell checking |
95621c8
to
09a58c5
Compare
@jklymak test added. I not insist on this change -- I thought that it may be useful for many users so I push it, but if you think it may be incompatible just discard it. |
I think this description in matplotlib/lib/matplotlib/figure.py Lines 1197 to 1200 in d09526f
|
@tacaswell’s suggestion of converting any iterable to a list would allow the user to pass |
Allow to pass a tuple of axes as "ax" parameter of make_axes function Signed-off-by: Strzelczyk, Piotr <piotr.strzelczyk@intel.com>
09a58c5
to
a928cec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PiotrStrzelczykX thanks for the update. The docstrings all look consistent with the change now.
I still think that if we support all sequences, it is worth expanding to support all iterables:
- as @tacaswell notes, containing questions about types in that initial loop and always coming out of that loop with a list is more robust.
dict.values()
seems like a likely thing to want to pass (and is not a sequence).- I suspect that a lot of users would not know off hand the difference between a sequence and an iterable (I always have to look it up!) so it’s just easier from the user point of view if the more general object is supported.
Having said all that, I am just a contributor and have no authority here, so we need to wait for a decision from the core developers.
I think we should actually figure out a consistent way to deal with itterables and perhaps factor it into I wonder if co-ercing to numpy array first is a good consistent way to do this? Then we are just relying on their broadcasting rules, which is easy to explain. eg |
|
The code provided by @tacaswell enforces that it is a |
@PiotrStrzelczykX, thank you for this PR. In fact, I tripped over this (not accepting a tuple argument) myself a week or two ago. We will be happy to accept the PR either as-is, or after one more change, if you choose to make it: specifically, the suggestion by @tacaswell, and endorsed by @rcomer and myself, to broaden the supported types to include iterables, like if np.iterable(parents):
if isinstance(parents, np.ndarray):
parents = list(parents.flat)
else:
parents = list(parents)
else:
parents = [parents] If you do choose to make this change, then where you have "sequence" in the docstring it would become the more general "iterable". It is possible that some time later, after merging the PR, we might factor this argument-handling functionality out for use in other places; but we don't want to stall the PR while hashing out larger questions of API design and factoring. |
Also, if you choose to make the change, you could add a line to the test: fig.colorbar(im, ax=dict(a=ax[0], b=ax[1]).values()) |
I just noticed that the constrained layout guide states
https://matplotlib.org/stable/tutorials/intermediate/constrainedlayout_guide.html#colorbars @PiotrStrzelczykX could you let us know if you intend to take this any further? As @efiring said, we are happy to merge as is. However, it would be better not to merge yet if you are planning to push further changes. |
Thank you for your work on this @PiotrStrzelczykX and congratulations on your first merged Matplotlib PR 🎉 I hope we hear from you again! |
PR Summary
Allow to pass a tuple of axes as "ax" parameter of make_axes function.
It restores functionality available in this function, before memory leak fix
(in PR: #22089 ).
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst