Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow bool-like values for sharex/sharey#24362

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
timhoffm merged 8 commits intomatplotlib:mainfromvdbma:fix-sharey
Dec 16, 2022

Conversation

vdbma
Copy link
Contributor

@vdbmavdbma commentedNov 4, 2022
edited
Loading

PR Summary

This PR allows to use either 0 or 1 in place ofFalse orTrue insharex andsharey options.Fixes#24349.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes). (everything passes excepttest_font_manager.py::test_get_font_names, and it would seem that it is because I have custom fonts installed)
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

@vdbma
Copy link
ContributorAuthor

I am not super happy with the implementation :

_api.check_in_list(["all","row","col","none",0,1,False,True]

The error message is clearer but with the if conditions above,False,True, 0 and 1 are not actually values that can be passed tosharex andsharey. In this case their value is changed to'all' or'none'.

Copy link

@github-actionsgithub-actionsbot left a 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 uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@tacaswelltacaswell added this to thev3.7.0 milestoneNov 4, 2022
Copy link
Member

@timhoffmtimhoffm left a comment
edited
Loading

Choose a reason for hiding this comment

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

If I have understood the dev cal discussion from yesterday correctly, the way forward here is not special-handling 0 and 1 but

  • remove theisinstance(sharex, Integral) check. That warning is not needed anymore because sharex is keyword-only now.
  • rewrite the code to special-handle str, and bool-ducktype any other value, i.e.
    if isinstance(sharex, str):    ...else:    sharex = "all" if sharex else "none"

anntzer reacted with thumbs up emoji
@jklymak
Copy link
Member

@vdbma, is the comment about the code re-organization from@timhoffm above clear?

@vdbma
Copy link
ContributorAuthor

Yes very clear, thanks for the feedback ! I will implement it when I have some time.

@vdbma
Copy link
ContributorAuthor

vdbma commentedNov 8, 2022
edited
Loading

I implemented what you suggested, but there are still two points that bother me and to which I did not find an elegant solution (yet):

  • As was discussed above_api.check_in_list is what formats the error message. However the values thatsharex takes when this function is called already has been normalised to one of"all", "row", "col", "none". Thus it will never occur thatsharex still has one of the values0, 1, False, True , yet we still check that it might. But we can't remove the "useless" values, because then the error message would not be clear regarding what values are allowed for the user to use. This feels somewhat inconsistent to me.
  • With the current implementation (suggested by@timhoffm) passing any other integer/float value than 0 or 1 is not a problem. Do we actually want this behaviour ? (if so the test added intest_subplots.py::test_shared should be removed)

@timhoffm
Copy link
Member

  • As was discussed above_api.check_in_list is what formats the error message. However the values thatsharex takes when this function is called already has been normalised to one of"all", "row", "col", "none". Thus it will never occur thatsharex still has one of the values0, 1, False, True , yet we still check that it might. But we can't remove the "useless" values, because then the error message would not be clear regarding what values are allowed for the user to use. This feels somewhat inconsistent to me.

The fundamental issue here is that the logic needs special handling of some of the existing values. Thus, the_check_in_list() site does not see the full range of possible values. As long as we build the message from the check list, we either lack allowed values in the message or we have to extend the list beyond what can actually be used in the current context.

I'm mostly ok to have the extra values in here. - The alternative would be to expand the semantics of the_print_supported_values parameter so that we can do:

check_in_list(    ["all", "row", "col", "none"],    _print_supported_values=["all", "row", "col", "none", True, False],    sharex=sharex, sharey=sharey)
  • With the current implementation (suggested by@timhoffm) passing any other integer/float value than 0 or 1 is not a problem. Do we actually want this behaviour ? (if so the test added intest_subplots.py::test_shared should be removed)

Yes. To be clear: Conceptually, we don't accept special values 0, 1 as synonyms to True and False. We only support the concept of duck-typing, which says that you can pass any truthy or falsy values. This is also what happens in most cases automatically when you have conditions likeif sharex:.

N.b.: For that reason, the check in list message shouldnot list 0, 1 explicitly.

@vdbma
Copy link
ContributorAuthor

Thanks you for the feedback ! I better understand the logic.

tacaswell
tacaswell previously requested changesNov 23, 2022
Copy link
Member

@tacaswelltacaswell left a comment

Choose a reason for hiding this comment

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

Please do not remove the test.

Anyone can dismiss this review.

@tacaswell
Copy link
Member

@vdbma are you still interested in working on this PR?

I'm going to push this to 3.8, but if it is done there is no reason it can not be merged for 3.7.

@tacaswelltacaswell modified the milestones:v3.7.0,v3.8.0Dec 15, 2022
@vdbma
Copy link
ContributorAuthor

Yes, very much so ! Sorry for the late contribution.

@vdbma
Copy link
ContributorAuthor

vdbma commentedDec 15, 2022
edited
Loading

As of now the documentation forsharex says:

...
sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False
Controls sharing of properties among x (sharex) or y (sharey) axes:
True or 'all': x- or y-axis will be shared among all subplots.
False or 'none': each subplot x- or y-axis will be independent.
...

Should I change it so that it is explicit that non-str values will be cast to boolean or should it remain an implicit behaviour ?

@timhoffm
Copy link
Member

timhoffm commentedDec 15, 2022
edited
Loading

Please leave it as is. The primary logic type here isbool. That many things can be interpreted as bool is a language property of Python, which is often used. It would be rather distracting to mention this in every context that supports it.

@tacaswell
Copy link
Member

Yes, very much so ! Sorry for the late contribution.

Great and no worries!

@tacaswelltacaswell dismissed theirstale reviewDecember 15, 2022 23:42

test re-added.

@QuLogicQuLogic changed the titleUsing 0 or 1 as bool in sharex/shareyAllow bool-like values for sharex/shareyDec 15, 2022
@QuLogic
Copy link
Member

QuLogic commentedDec 15, 2022
edited
Loading

This could do with a squash, by you if you're comfortable with it, or at merge time.

@timhoffmtimhoffm merged commit2828912 intomatplotlib:mainDec 16, 2022
@timhoffm
Copy link
Member

I've squashed during merge.

@vdbma thanks, and congratulations on your first contribution to Matplotlib! We hope to see you again.

@timhoffmtimhoffm modified the milestones:v3.8.0,v3.7.0Dec 16, 2022
raphaelquast pushed a commit to raphaelquast/matplotlib that referenced this pull requestMar 16, 2023
Co-authored-by: Marc Van den Bossche <marc.vanden-bossche@univ-grenoble-alpes.fr>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@jklymakjklymakjklymak left review comments

@astromancerastromancerastromancer left review comments

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@QuLogicQuLogicQuLogic approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

@tacaswelltacaswelltacaswell left review comments

Assignees
No one assigned
Projects
None yet
Milestone
v3.7.0
Development

Successfully merging this pull request may close these issues.

[Bug]: sharex and sharey don't accept 0 and 1 as bool values
6 participants
@vdbma@jklymak@timhoffm@tacaswell@QuLogic@astromancer

[8]ページ先頭

©2009-2025 Movatter.jp