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

ENH: Stricter validation of line style rcParams (and extended accepted types forgrid.linestyle)#8040

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

Conversation

afvincent
Copy link
Contributor

@afvincentafvincent commentedFeb 7, 2017
edited
Loading

A possible “solution” to#7991 (suggested by@tacaswell on Gitter,February 7, 2017 12:09 PM) . The user could now use a sequence like [1.0, 3.0] for the rcParamgrid.linestyle.

The validation is not extensive, partly because I was not sure it should be performed here. For example, one can perfectly pass a value like u'Hello world' without the new functionvalidate_grid_linestyle raising an error. Should I set the only accepted strings to be incbook.ls_mapper andcbook.ls_mapper_r?

Edit: typo + link to Gitter.

@afvincentafvincent added this to the2.0.1 (next bug fix release) milestoneFeb 7, 2017
@tacaswell
Copy link
Member

It does not make the validation weaker at least.

@afvincent
Copy link
ContributorAuthor

I could make the validation stronger in the case of strings if you think it is better.

@afvincentafvincent mentioned this pull requestFeb 7, 2017
pass

raise ValueError("'grid.linestyle' must be a string or " +
"a even-length sequence of floats.")
Copy link
ContributorAuthor

@afvincentafvincentFeb 7, 2017
edited
Loading

Choose a reason for hiding this comment

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

Note to myself for tomorrow: “an even” (done)

@dopplershift
Copy link
Contributor

Shouldn't this be applied for all linestyles, not just grid?

@tacaswell
Copy link
Member

👍 to@dopplershift suggestion to add this to all of the rcparams that take linestyle.

Interestingly, for negative contours, there is a commit from 2007 (4682b0c) which deprecated passing in that linestyle as a on/off pattern.

@afvincent
Copy link
ContributorAuthor

I am not sure it is exactly the same situation:

  • for “normal” line styles, the non solid patterns are defined through the ad-hoc rcParams (e.g.lines.dashed_pattern), and then the rcParamlines.linestyle is expected to be a named one, in {'solid', '-', 'dashed', '--', 'dashdot', '-.', 'dotted', ':'}. Introducing the possibility to pass directly a on-off sequence seems to be doing twice the job to me :/.
  • for the rcParamgrid.linestyle, the idea was to relax the validation to also accept on-off sequencesbecause we did not want to introduce the equivalent rcParams likegrid.dashed_patterns to avoid excessive granularity, but still wanted to give the possibility to use a non solid line style that is different from the “normal” ones.

By the way, I have the feeling that the deprecated validation for the negative contour line style is a bit restrictive: it seems like only 2-element sequences are accepted (i.e. [3, 1, 1, 1] would be rejected for example, if I am correct…).

@dopplershift
Copy link
Contributor

Counterpoint: why on earth, from a user standpoint, is configuring grid linestyle different from the other linestyles? I get the programmer concerns, but from a UX perspective, we're giving users a new thing to learn with no justification. Feels like a set of features that grew over time (which it is) rather than a cohesive design (which is what people want).

@afvincent
Copy link
ContributorAuthor

Fair enough :), I am going to relax the validation of all the 'linestyle' rcParams, i.e.:

In [4]: [keyforkeyinplt.rcParamsifu'linestyle'inkey]Out[4]: [u'boxplot.boxprops.linestyle',u'boxplot.capprops.linestyle',u'boxplot.flierprops.linestyle',u'boxplot.meanprops.linestyle',u'boxplot.medianprops.linestyle',u'boxplot.whiskerprops.linestyle',u'contour.negative_linestyle',# beware of the existing deprecationu'grid.linestyle',u'lines.linestyle']

to accept on-off sequences.

@afvincent
Copy link
ContributorAuthor

Now all the rcParams related to a line style (butcontour.negative_linestyle) can be passed an on-off ink sequence. Besides, I added an early check that if a string is given, then it has to be one that will be accepted byLine2D.set_linestyle.

How should I handle the case ofcontour.negative_linestyle? It seems like a long time ago, one could pass an on-off ink sequence, but then is was deprecated to only accept a named line style (seevalidate_negative_linestyle_legacy inrcsetup.py). Should I deprecate the deprecation (\o/) to use the new validatorvalidate_linestyle too?If it is, what has to be done: where can I find doc on the (current) deprecation process?

@afvincent
Copy link
ContributorAuthor

Sorry, my current text editor does not yell at me when scripts are not PEP8-compliant… The other CI failure does not seem related (about “mathtext_dejavusans_21”).

@efiring
Copy link
Member

efiring commentedFeb 9, 2017 via email

On 2017/02/09 9:08 AM, Adrien F. Vincent wrote: How should I handle the case of |contour.negative_linestyle|? It seems like a long time ago, one could pass an on-off ink sequence, but then is was deprecated to only accept a named line style (see |validate_negative_linestyle_legacy| in |rcsetup.py|). Should I deprecate the deprecation (\o/) to use the new validator |validate_linestyle| too? /If it is, what has to be done: where can I find doc on the (current) deprecation process?/
I think all you have to do is remove the deprecation stuff and use thenew validator.

@afvincent
Copy link
ContributorAuthor

I removed the former validatorsvalidate_negative_contour andvalidate_negative_contour_legacy, to now consistently rely on the new validator for all the line style-related rcParams.

There may be a (minor) break of behavior: in the new validator, I have chosen to be case-sensitive (to discourage users' jokes like “DaSHdOtTed”), while the former validator forcontour.negative_linestyle was not (theignorecase kwarg was set to True).Was this a mistake?


# A validator for all possible line styles, the named ones *and*
# the on-off ink sequences.
def validate_linestyle(ls):
Copy link
Member

Choose a reason for hiding this comment

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

can we make this a private function? I don't think it should be added to our public API.

dopplershift reacted with thumbs up emoji
NelleV
NelleV previously requested changesFeb 13, 2017
@@ -888,6 +872,36 @@ def validate_animation_writer_path(p):
modules["matplotlib.animation"].writers.set_dirty()
return p

# A validator dedicated to the named line styles, based on the items in
# ls_mapper, and a list of possible strings read from Line2D.set_linestyle
validate_named_linestyle = ValidateInStrings('linestyle',
Copy link
Member

Choose a reason for hiding this comment

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

same here. this should not appear in our public API.

dopplershift reacted with thumbs up emoji
Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Ok I'll do that! (I was hesitating because most of the other validators are public).

Speaking of public API, I think I've done something wrong (:sheep:) by genuinely getting rid off ofvalidate_negative_linestyle andvalidate_negative_linestyle_legacy as they were both part of the public API. I should have used some deprecation warning instead, shouldn't I? Or at least just leave them (because ifvalidate_linestyle is made private, there will be no alternative)?

@WeatherGod
Copy link
Member

WeatherGod commentedFeb 13, 2017 via email

hmmm, my knee-jerk reaction is that maybe it should remain case-insensitivewith a deprecation to become case-sensitive? I don't remember, but arecolors case-sensitive? If they are case-insensitve, then maybe it makessense for everything to be case-insensitive.
On Fri, Feb 10, 2017 at 4:36 AM, Adrien F. Vincent ***@***.*** > wrote: I removed the former validatorsvalidate_negative_contour and validate_negative_contour_legacy, to now consistently rely on the new validator for all the line style-related rcParams. There may be a (minor) break of behavior: in the new validator, I have chosen to be case-sensitive (to discourage users' jokes like “DaSHdOtTed”), while the former validator for contour.negative_linestyle was not (the ignorecase kwarg was set to True). *Was this a mistake?* — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub <#8040 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AARy-JQKMBBMs12sXCxP6J8Vw7l8sKZIks5rbC-zgaJpZM4L5reS> .

@dopplershift
Copy link
Contributor

dopplershift commentedFeb 13, 2017
edited
Loading

I'm only in favor of limiting user choice to prevent dangerous behavior/common mistakes--not silly/poor choices.

Having said that, it's much more important to me for it to be consistent with the rest of the library (like@WeatherGod said).

@afvincent
Copy link
ContributorAuthor

From what I understand, color validation is case insensitive. In_to_rgba_no_colorcycle, which is called during the process, one can read:

...# Named color.try:# This may turn c into a non-string, so we check again below.c=_colors_full_map[c.lower()]...

wherec is the “color” under test. However on the 20+ instances ofValidateInStrings, more than half of themare case sensitive.

Anyway, I guess that making_validate_linestyle case insensitive will not be dangerous and it will avoid a deprecation process to warn people that would have been using named line styles not fully in lower case for negative contours.

tacaswell reacted with thumbs up emoji

@afvincent
Copy link
ContributorAuthor

The new validation scheme is now private and case-insensitive :).

I have reintroduced the former validators related to thecontour.negative_linestyle rcParam, because they were part of the public API. I have nonetheless added a (lazy) deprecation warning about them. Not totally sure I followed the canonical way to do this though :/.

@afvincent
Copy link
ContributorAuthor

One last thing that bothers me a bit is that the (newly deprecated) former validatorsvalidate_negative_linestyle andvalidate_negative_linestyle_legacy do not seem bugfree (but even before this PR they were not tested, so it seems to have stayed under the radar…). See for example this traceback when (the current)validate_negative_linestyle_legacy is called with a simple 2-element list:

---------------------------------------------------------------------------AttributeErrorTraceback (mostrecentcalllast)<ipython-input-2-667b565f2256>in<module>()---->1validate_negative_linestyle_legacy([1,2])/home/adrien/matplotlib/lib/matplotlib/cbook/deprecation.pycinwrapper(*args,**kwargs)204defwrapper(*args,**kwargs):205warnings.warn(message,mplDeprecation,stacklevel=2)-->206returnfunc(*args,**kwargs)207208old_doc=textwrap.dedent(old_docor'').strip('\n')/home/adrien/matplotlib/lib/matplotlib/rcsetup.pycinvalidate_negative_linestyle_legacy(s)549defvalidate_negative_linestyle_legacy(s):550try:-->551res=validate_negative_linestyle(s)552returnres553exceptValueError:/home/adrien/matplotlib/lib/matplotlib/cbook/deprecation.pycinwrapper(*args,**kwargs)204defwrapper(*args,**kwargs):205warnings.warn(message,mplDeprecation,stacklevel=2)-->206returnfunc(*args,**kwargs)207208old_doc=textwrap.dedent(old_docor'').strip('\n')/home/adrien/matplotlib/lib/matplotlib/rcsetup.pycinvalidate_negative_linestyle(s)540"deprecation warning for more information."))541defvalidate_negative_linestyle(s):-->542return_validate_negative_linestyle(s)543544/home/adrien/matplotlib/lib/matplotlib/rcsetup.pycin__call__(self,s)64def__call__(self,s):65ifself.ignorecase:--->66s=s.lower()67ifsinself.valid:68returnself.valid[s]AttributeError:'list'objecthasnoattribute'lower'

I think it may be fixed by simply catchingAttributeErrorexception in the same way asValueError exceptions are caught invalidate_negative_linestyle_legacy.Should I do this fix too, or is it not worth it due to the deprecation?

@afvincent
Copy link
ContributorAuthor

The Travis failure seems unrelated to this PR. It is complaining abouttest_mixedsubplots inmplot3d, which has been rather flaky recently.

@WeatherGod
Copy link
Member

WeatherGod commentedFeb 14, 2017 via email

Probably not worth it.
On Mon, Feb 13, 2017 at 7:54 PM, Adrien F. Vincent ***@***.*** > wrote: One last thing that bothers me a bit is that the (newly deprecated) former validators validate_negative_linestyle and validate_negative_linestyle_ legacy do not seem bugfree (but even before this PR they were not tested, so it seems to have stayed under the radar…). See for example this traceback when (the current) validate_negative_linestyle_legacy is called with a simple 2-element list: ---------------------------------------------------------------------------AttributeError Traceback (most recent call last)<ipython-input-2-667b565f2256> in <module>()----> 1 validate_negative_linestyle_legacy([1, 2]) /home/adrien/matplotlib/lib/matplotlib/cbook/deprecation.pyc in wrapper(*args, **kwargs) 204 def wrapper(*args, **kwargs): 205 warnings.warn(message, mplDeprecation, stacklevel=2)--> 206 return func(*args, **kwargs) 207 208 old_doc = textwrap.dedent(old_doc or '').strip('\n') /home/adrien/matplotlib/lib/matplotlib/rcsetup.pyc in validate_negative_linestyle_legacy(s) 549 def validate_negative_linestyle_legacy(s): 550 try:--> 551 res = validate_negative_linestyle(s) 552 return res 553 except ValueError: /home/adrien/matplotlib/lib/matplotlib/cbook/deprecation.pyc in wrapper(*args, **kwargs) 204 def wrapper(*args, **kwargs): 205 warnings.warn(message, mplDeprecation, stacklevel=2)--> 206 return func(*args, **kwargs) 207 208 old_doc = textwrap.dedent(old_doc or '').strip('\n') /home/adrien/matplotlib/lib/matplotlib/rcsetup.pyc in validate_negative_linestyle(s) 540 "deprecation warning for more information.")) 541 def validate_negative_linestyle(s):--> 542 return _validate_negative_linestyle(s) 543 544 /home/adrien/matplotlib/lib/matplotlib/rcsetup.pyc in __call__(self, s) 64 def __call__(self, s): 65 if self.ignorecase:---> 66 s = s.lower() 67 if s in self.valid: 68 return self.valid[s] AttributeError: 'list' object has no attribute 'lower' I think it may be fixed by simply catching AttributeErrorexception in the same way as ValueError exceptions are caught in validate_negative_linestyle_legacy. *Should I do this fix too, or is it not worth it due to the deprecation?* — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#8040 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AARy-NIs-OGzC-_gEfX-W1zL2jDaFlY9ks5rcPstgaJpZM4L5reS> .



@deprecated('3.0.0?', pending=True,
Copy link
Member

Choose a reason for hiding this comment

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

Why can't we deprecate this "for sure"?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

So, something like

@deprecated(theversionnumberyouwillkindlysuggest,# :)addendum=(" See 'validate_negative_linestyle_legacy' "+"deprecation warning for more information.")            )

would be better?

Copy link
Member

Choose a reason for hiding this comment

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

Yes :D
I suggest deprecating this in 2.1, which means no backporting. Is that a problem?

@NelleVNelleV dismissed theirstale reviewFebruary 16, 2017 19:32

All comments have been addressed

@NelleVNelleV changed the titleENH: Extend accepted type for the rcParamgrid.linestyle[MRG+1] ENH: Extend accepted type for the rcParamgrid.linestyleFeb 16, 2017
@NelleV
Copy link
Member

I'd like to understand why the deprecations are pending, and why we are deprecating for 3.0.0 (and not for 2.3). Else it looks good (I'll approve one@afvincent clarifies this point).

@afvincent
Copy link
ContributorAuthor

@NelleVWell… It simply reflects that I do not understand how the process of deprecation goes ^^…
Does “deprecated in 2.x” means
i) “This function should not be used anymore and might disappear in release 2.x + 0.2 and beyond”, or
ii) “This function might disappear at any moment since release 2.x”?
Then in case i) the deprecation should start at 2.0.1 (milestone of this PR), while in case ii) it should be 2.2 (or even later?).
For me, the current@deprecated decorators mean “We might remove this function after mpl 3 is released”, and thepending=True was used to avoid the message to beThe ... function was deprecated in version 3.0.0. ..., which sounds weird. But apparently I am wrong and they are only meaning this to my eyes, so I will be happy to change the@deprecated decorators for the version number that you prefer ;) (and I will removepending=True).

@afvincent
Copy link
ContributorAuthor

Sidenote: I think awhat's new entry might be a good thing. Unless anybody stand up against it, I will add one at the same time I will update the@deprecated decorators (likely tomorrow from this side of the Atlantic ocean).

@NelleV
Copy link
Member

Deprecated in 2.1 means it will be removed in 2.3.
We should not deprecate for 2.0.1 as deprecation should not happen in micro releases (but integrating the code with the warning that it is deprecated in 2.1 and removed in 2.3 is totally fine with me).

👍 on the what's new entry.

@tacaswelltacaswell modified the milestones:2.1 (next point release),2.0.1 (next bug fix release)Feb 17, 2017
@tacaswell
Copy link
Member

I think it is fine to push this to 2.1 (changed my mind).

@afvincent
Copy link
ContributorAuthor

Ok, the deprecations now start at 2.1. And I have added awhat's new entry. Maybe it would be wise if an native English-speaker could have a look.

PS: I have changed the PR title because actually all line style rcParams are now affected by this PR ;).

@afvincentafvincent changed the title[MRG+1] ENH: Extend accepted type for the rcParamgrid.linestyle[MRG+1] ENH: Stricter validation of line style rcParams (and extended accepted types forgrid.linestyle)Feb 17, 2017
@NelleVNelleV merged commit6450ce2 intomatplotlib:masterFeb 18, 2017
@NelleV
Copy link
Member

Thanks!

@QuLogicQuLogic changed the title[MRG+1] ENH: Stricter validation of line style rcParams (and extended accepted types forgrid.linestyle)ENH: Stricter validation of line style rcParams (and extended accepted types forgrid.linestyle)Feb 19, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@NelleVNelleVNelleV left review comments

@tacaswelltacaswelltacaswell approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v2.1
Development

Successfully merging this pull request may close these issues.

6 participants
@afvincent@tacaswell@dopplershift@efiring@WeatherGod@NelleV

[8]ページ先頭

©2009-2025 Movatter.jp