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

Validate text rotation in setter #19228

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
QuLogic merged 1 commit into matplotlib:main from dstansby:validate-rotation
Jan 5, 2022
Merged

Conversation

Copy link
Member

@dstansby dstansby commented Jan 3, 2021

xref #19223. I think checking for numbers.Real is the right thing to do here?

if isinstance(s, str):
_api.check_in_list(['vertical', 'horizontal'], rotation=s)
elif s is not None:
cbook._check_isinstance(numbers.Real, s=s)
Copy link
Contributor

Choose a reason for hiding this comment

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

either both should be s=s, or both should be rotation=s, depending on whether you want to strictly match the kwarg name, or use a semantically more meaningful name.

Copy link
Member

@timhoffm timhoffm Mar 1, 2021

Choose a reason for hiding this comment

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

Both should be rotation=s. It's understandable in the context of set_rotation() as well as in Text(..., rotation=).
For the latter s=s would result in "'invalid string' is not a valid value for s" which is quite unhelpful.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

modulo my comment, which is not strictly necessary, though.

@@ -232,7 +232,7 @@ def test_add_subplot_invalid():
def test_suptitle():
fig, _ = plt.subplots()
fig.suptitle('hello', color='r')
fig.suptitle('title', color='g', rotation='30')
fig.suptitle('title', color='g', rotation=30)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess strictly speaking this is backcompat breaking? I doubt it's worth a deprecation period, but it should be noted.

Copy link
Member

@timhoffm timhoffm Mar 1, 2021

Choose a reason for hiding this comment

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

Not even sure we need to mention it. '30' is not a supported format according to docs. It just happens to work. If we drop that without deprecation period, a note does not really help anybody. Nobody goes through the note and says "hey rotation does not take string numbers anymore. That's my thing, I'm doing that all the time". I'll bet anything if anybody passes '30', they will only notice by the error message they will get.

jklymak and anntzer reacted with thumbs up emoji
Copy link
Member

timhoffm commented Apr 5, 2021
edited
Loading

@dstansby please change to cbook._check_isinstance(numbers.Real, rotation=s). See the open comment above.

@jklymak jklymak marked this pull request as draft April 23, 2021 17:01
Copy link
Member Author

I finally got round to rebasing this, so should be good for review again.

Copy link
Member

@@ -1177,6 +1178,10 @@ def set_rotation(self, s):
The rotation angle in degrees in mathematically positive direction
(counterclockwise). 'horizontal' equals 0, 'vertical' equals 90.
"""
if isinstance(s, str):
Copy link
Member

Choose a reason for hiding this comment

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

The two separate checks lead to slightly confusing messages as they don't mention the respective other valid parameters, e.g.

ValueError: '30' is not a valid value for rotation; supported values are 'vertical', 'horizontal'

does not mention numbers.

I'd go for a manual check and message here:

if s is not None and not isinstance(s, numbers.Real) and s not in ['vertical', 'horizontal']:
 Raise ValueError("rotation must be 'vertical', 'horizontal' or a number, not {s!r}"]

dstansby reacted with thumbs up emoji
@dstansby dstansby marked this pull request as ready for review December 28, 2021 15:09
@QuLogic QuLogic merged commit 2465eff into matplotlib:main Jan 5, 2022
@dstansby dstansby deleted the validate-rotation branch January 5, 2022 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@QuLogic QuLogic QuLogic left review comments

@anntzer anntzer anntzer approved these changes

@timhoffm timhoffm timhoffm approved these changes

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

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /