-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Rcparam validation fix #3564
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
Rcparam validation fix #3564
Conversation
Close matplotlib#3470 Over-ride `update` so that inputs are validated.
Simplify and relax the validation for sequences of floats and ints. - unified logic - input is not restricted to coma-separated lists, list, and tuples. any length 2 sequence (like an array) will now work.
@@ -849,6 +849,16 @@ def __getitem__(self, key): | |||
key = alt | |||
return dict.__getitem__(self, key) | |||
|
|||
# http://stackoverflow.com/questions/2390827/how-to-properly-subclass-dict-and-override-get-set |
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 don't think the comment is necessary (at all), but a test would be very welcome.
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.
The comment could be shortened to one or two lines, but noting why update needs to be overridden is helpful; it's not obvious.
In principle, 👍. Some minor tweaks and a couple of trivial tests would push this over the line 😉 |
This seems to break saving animations and I have no idea why... |
And it works if you run the test code in ipython but not when nose runs it... |
This is a minor api change, but I can't think of why one would want to carry around empty strings.
The animation failures seem to be from the fact that a) the default values for When I have fixed this two ways a) updated the default values and b) change the This patch also causes 3 warnings to be raised as they get validated on the update with the default step. |
Same as `update`, the default behavior of `dict.__init__` does not call `__setitem__` so we have not been validating values passed at creation time. Update the tests to account for the validation.
- assert raise on invalid update - assert raise on invalid init
@pelson Can you take another look at this? I want to tag 1.4.1rc1 tonight. |
gah, this seems to have now broken the build (due to unicode issues) and something strange with 2.6 and |
and I really should do something about the warnings on obsolete rcparams |
I think the better solution is to filter them out when creating the default rcparamdict (working on it) |
suppresses possibly scary warnings
Mostly paranoia
re-use the existing frame work for this
I'm running home now, but there is sufficient uncertainty with this PR that is bothers me to merge and then immediately release a v1.4.1. What impact does the bug you're having fix? Is it worth holding this PR back for us to see a v1.4.1 through, and then apply this change subsequently (knowing that there is a real chance that we may not actually release a v1.4.2 and go straight to v1.5.0...). @tacaswell - what do you think on the matter? |
Without this fix pandas, networkx, and seaborn all can blow up with very cryptic errors using the macosx backend. This affects enough of the code that I would rather get this into 1.4.1 and do a 1.4.2 if we have to when we find corner cases that didn't have test coverage rather than merge this later and then have it go out in 1.5.0 and have those same issues come up then after we have forgotten all of the details of this PR and will have a bunch of other hair-on-fire issues. This bug has probably been there sense we did the sixification, but apparently no one uses the dev version + macosx + the styles in any of those packages. |
@matplotlib/developers Can this get reviewed and get a consensus yes/no on if this should be in 1.4.1. As I said above, I am in favor getting this in as soon as possible. |
I agree; I think it makes sense to include it in 1.4.1. @pelson's factorization suggestion would be nice, but can always be done later. |
Are we still stuck with the issue of individual characters getting through On Sat, Oct 4, 2014 at 4:04 PM, Eric Firing notifications@github.com
|
@WeatherGod This in fact fixes the problems with the keymap parameters |
The other fixes on this branch make this un-needed (as the default values of are now properly validated and a single word string (as separated by commas) are correctly converted into length 1 list) but out of principle make the default value of things labeled an 'string lists' should have default values which are lists of strings.
I'm actually falling on the other side of the fence - there will projects which depend on mpl which worked with v1.4.0 and not with v1.4.1 as a result of this change. I agree that they are making use of an API which we did not promise wouldn't break in the future, but the fact remains that there will be projects which are setting values which make zero difference to the resulting figure yet are not valid rcParameters. As a result of this change, the code will no longer work - I'm OK with forcing that issue, but not in a patch release (from v1.4 -> v1.5 would be a far better option). Let me make this concrete. v1.4.0 (fine):
v1.4.1 (errors with
Of course, the actual problems will be far more subtle (lists vs scalars being the obvious problems).
The workaround would be to add warning to the update method if there are bad rcParameters for the intermediate v1.4.1 release.
What I'm lacking is a concrete example where you found this problem. Is this a seaborn rcParam which is being set, or is it a case of users updating the rcParam dict incorrectly? If the former, then are we instantly going to break old versions of, for example, seaborn when using mpl 1.4.1? |
When I get back to ny I will wrap the up date and init validation in try except blocks + warnings. What I don't see is a use case where a value in the rcparams fails the validation, but works correctly when used. I see this a making the api do what we always claimed it did, not changing the api. |
This is a tough call. I agree with @tacaswell that all we're doing is enforcing an API that was already there, not changing the API. However, as this isn't really fixing a regression since 1.3 and it's so pervasive, maybe we'd better, as @pelson suggests, warn for now, and throw exceptions in 1.5... |
Catch exceptions raised due to failed validations, force setting the (un validated!) value, and print a warning.
@pelson example now runs, but prints a warning.
|
Added known-fail to tests that expect rcparam __init__ and update to raise exceptions on invalid input.
Probably one last thing to do is double-check the keymap. This isn't covered in the unit tests. |
@WeatherGod Added test. |
Looks solid and all comments above have been addressed so I will merge this now. |
Sorry to not have replied on this. What I meant was to double-check that the keymap handling code still works. To actually open up a plot and press all of the keys, making sure they still work. |
Just checked and they work (couldn't test cmd-w as i don't have a mac and I'm not sure what 'keymap.all_axes' does). I suspect there is some code in that handling which can be simplified, but I don't really want to touch that right now. |
Good enough for me! Thanks! On Tue, Oct 14, 2014 at 11:39 AM, Thomas A Caswell <notifications@github.com
|
Oh, and as for fixing up the keymap handling, after I finish my book, I will probably put together a MEP for a vastly improved keymap system that would allow users to extend its functionality (along with other features). |
Fixes an imaginary bug, a real bug, and a bug discovered while fixing the real bug.
This should get tests before it gets merged.