-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Support only positional args in contour. Error if no positional argument. #24749
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
Conversation
@oscargus can you take a look at this? I've added some logic to support kwargs too. Let me know if you want to add these changes to the other PR and close this. Thanks! |
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.
Subject to green etc.
(And possibly the "black-like" formatting... ;-))
(One may consider reordering the logic a bit, but that is only my micro-optimization mindset talking. Like
if "Z" in kwargs:
if "X" ... and ...
elif "X" ... ^ ...
else:
elif 0 < nargs...
but it may be that other people prefer to have it more understandable...)
This is much better than mine!
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 think the type of the raised error needs to be changed.
Anyone can dismiss this review.
Updated, @tacaswell. |
805e4f0
to
cba8e7d
Compare
lib/matplotlib/contour.py
Outdated
"Both or neither 'X' and 'Y' may be passed as kwargs. " | ||
"Passing only one of the two is not allowed." |
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.
"Both or neither 'X' and 'Y' may be passed as kwargs. " | |
"Passing only one of the two is not allowed." | |
"Passing only one of 'X' or 'Y' is not allowed." |
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.
Updated.
lib/matplotlib/contour.py
Outdated
) | ||
elif (("X" in kwargs) ^ ("Y" in kwargs)) and "Z" in kwargs: | ||
raise TypeError( | ||
"Both or neither 'X' and 'Y' may be passed as kwargs. " |
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.
"Both or neither 'X' and 'Y' may be passed as kwargs. " |
You don't need to say both, and this phrase is extremely awkward.
Sorry for being late to the party. Are we sure we want to do this? Having positional-only parameters is not the end of the world. Note that we have a lot of similar functions, in which you cannot pass the coordinate parameters by keyword. I guess this holds for almost all functions that use I propose to instead only document that these parameters are keyword-only. Alternatively, maybe it's worth investigating whether this can be generalized into a decorator to keep the complexity out of the functions and make it applicable throughout the code base. @anntzer you come to my mind when it comes to such types of infrastructure code 😄 . |
See #11526 (comment) or #22303. I haven't checked whether the situation is different for contour (perhaps not having U, V makes things easier) but at first glance keeping parameters positional-only may be a good idea. If you want something more infrastruture-y, perhaps something along the lines of #7966 (comment) can be made to work (perhaps with a variant of select_matching_signature that displays all possible signatures in the exception thrown when an invalid call is made). |
Based on the discussion, I agree that having it just as positional and erroring out if the required arguments are not found would be better. I can change it to something like my original fix here #24747 (comment) Does that sound better? I also really like the idea of moving the parsing into a separate function as @anntzer did. I can see merits for first fixing this using just the positional arguments fix and then discussing about making a bigger change on the infra level but I'll defer that decision :) |
Based in this discussion I think we should push this to 3.8. |
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.
Hold for 3.8, anyone can dismiss this once 3.7.x is branched.
d8e791d
to
66a8722
Compare
I'm not sure why code coverage is failing. I've not added any untested lines. The report is about other files, it seems. |
Because for some reason no CI reported at all. |
Should I change anything then? |
Probably a rebase would fix it? |
66a8722
to
756eb1e
Compare
That seems to have at least triggered all the tests. Let's see. Thanks! |
Conflict caused by #24870 which changed the inside of the if/elif structure (and added a separate test, which also conflicts, but is more trivial as both should be kept) |
PR Summary
Closes #24743 (Extended from #24747)
Check if kwargs are passed for [X, Y], Z and if not, check that args has at least one element before accessing it.
PR Checklist
Documentation and Tests
pytest
passes)Release Notes
.. versionadded::
directive in the docstring and documented indoc/users/next_whats_new/
.. versionchanged::
directive in the docstring and documented indoc/api/next_api_changes/
next_whats_new/README.rst
ornext_api_changes/README.rst