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
Prevent 'color' argument to eventplot from overriding 'colors' kwarg (fixes #4297) #4298
Conversation
Seems more-or-less reasonable to me. I am inclined to raise, or at least warn, if the user passes in conflicting input. attn @efiring |
It looks like colors/color is not the only potential conflict here; maybe they can all be cleared up in one shot. I'm also wondering whether there might be a simple and more general way to handle this sort of thing, which seems to be a symptom of our loose handling of **kwargs. Maybe that should be considered separately. For the present PR, it might be enough to just loop over the pairs of potentially conflicting kwargs so as to handle all of them in a single simple loop. |
_color = kwargs.pop('color', None) | ||
# 'colors' kwarg should have a higher priority than 'color' | ||
if colors is None: | ||
colors = _color |
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.
Can you add an
else:
if _color is not None:
warnings.warn("'color' kwarg ignored")
or something to that effect?
@efiring I am fine with merging this (modulo the warning comment) now. The more general clean up should be done library wide and is a much bigger task than we want to pin on a new contributor. |
6b36357
to
7246263
Compare
Apologies for not following up on this sooner (I've been very busy this week). Following Eric's suggestion, I've added a function to |
7246263
to
3f7d083
Compare
# remove 'singular' keys from **kwargs dict in order to prevent them | ||
# being lazily passed as LineCollection props, where they override the | ||
# effect of the 'plural' versions (e.g. 'color' overrides 'colors') | ||
cbook.strip_problem_kwargs(kwargs, 'color', 'linewidth', 'linestyle') |
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.
This just discards the 'bad' kwargs which we can't do without a deprecation cycle. There are users out there that have been using color
that this will break. This needs to automate the precedence cascade.
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.
Yes, I thought that was your intent, based on your suggestion to add a warning to the effect of warnings.warn("'color' kwarg ignored")
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.
I wanted that warning only if the kwarg was actually ignored.
3f7d083
to
4a0eb3e
Compare
@tacaswell I think this now gives the behaviour you are looking for |
Enforces the priority of a local variable over a potentially conflicting | ||
argument in a kwargs dict, but falls back on the value of the keyword | ||
argument if the local variable's value is None. Raises an | ||
IgnoredKeywordWarning if the keyword argument is specified but ignored. |
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.
Can you please add numpydoc style Paramaters and Returns sections to this docstring?
Yes, thank you. Just a minor docstring change left (I hope), other than that lgtm to me. attn @efiring |
4a0eb3e
to
57f67e6
Compare
--------- | ||
out: any object | ||
If local_var is None then kwargs[kwarg_name] will be returned, | ||
otherwise local_var will be returned and an IgnoredKeywordWarning |
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.
This is not correct. -> "otherwise local_var will be returned. If kwargs[kwarg_name] has been overridden by local_var, an IgnoredKeywordWarning will be raised." Actually, I think the sentence about the warning should be in a separate "Raises:" block, shouldn't it?
57f67e6
to
4683061
Compare
@efiring I've written a more general version that can parse several keyword arguments in descending order of priority. The name, signature and docstring have also been changed according to your suggestions. |
b59bf4a
to
980e551
Compare
980e551
to
8b083c1
Compare
@tacaswell @efiring Are you happy with the new version? |
Looks good to me. |
Prevent 'color' argument to eventplot from overriding 'colors' kwarg (fixes #4297)
@alimuldal Thank you for the work and your patience working with us on revisions! |
Fixes issue #4297