Repository navigation
BUG [units]: fix signature incompatibilities between helper and helped functions - #15710
Conversation
|
Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.
|
|
👋 Thank you for your draft pull request! Do you know that you can use |
|
I've started fixing clear incompatibilities discovered with my test. The remaining failures are a mixed bag and will require more careful examination, as I suspect there are some false positives. |
b8fc2b2 to
6047c74
Compare
|
I found that |
6047c74 to
4a12859
Compare
4a12859 to
ad7be42
Compare
|
I'm hitting some failures that I don't immediately understand that apparently show that my parametrised test behaves funky when ran in parallel sessions ? |
|
It is interesting that the error happens in the test collection, not when the test is actually run in parallel. Maybe that's a symptom of the same limitation that already led you to duplicate the parameterize fixture? You could probably bypass that (at the cost of some more duplicated lines of code) by breaking the class up into separate test functions? |
yes I think it may be due to the fact that I used a consumable iterator ( |
28fdac2 to
95f4625
Compare
mhvk
left a comment
There was a problem hiding this comment.
Really nice! I need to look through the test function logic with perhaps a bit more detail, but I like how it already found quite a few little buglets (and numpy illogicalities!).
|
Thanks @mhvk for your review, I think I've addressed all your points ! |
60e160f to
89fbf28
Compare
|
Actually I think I found a simple-ish solution for |
mhvk
left a comment
There was a problem hiding this comment.
Just a few things; still have to go properly through the class you added (though it looks good!).
mhvk
left a comment
There was a problem hiding this comment.
OK, it is looking very good. Some comments on the actual test class, mostly to make it clearer (for me at least...)
Also, ideally the same tests are run for Masked, though I think it is fine to do that as follow-up...
| assert ( | ||
| have_args_helper and have_kwargs_helper | ||
| ), f"argument {nt!r} is not re-exposed as positional-or-keyword" | ||
| if pt.kind is VAR_POSITIONAL: |
There was a problem hiding this comment.
replace pt.kind with kt here too (or use pt.kind everywhere -- may be a bit clearer)
There was a problem hiding this comment.
elif statements seem redundant with continue (which I just added following another of your suggestions !), and having them all be if makes it slightly more readable (to me ?) because it forces alignement and makes it easier to spot differences.
| ), f"argument {nt!r} is not re-exposed as positional-or-keyword" | ||
| if pt.kind is VAR_POSITIONAL: | ||
| assert have_args_helper, "helper is missing a catch-all *args argument" | ||
| if pt.kind is VAR_KEYWORD: |
…ignatures TST: add meta tests for units.quantity_helper.function_helper to validate signature compatibility between helped and helper functions
473300d to
d8e7942
Compare
|
@mhvk I just integrated all your recent suggestions in a rebase. To help you reviewing again, I kept all changes more recent than your review in a separate commit, but everything else was squashed !
I'll add it to my todo list, and will work on it after this one is dealt with ! |
mhvk
left a comment
There was a problem hiding this comment.
One little buglet, otherwise all nitpicks - should be ready to go in with these addressed.
|
|
||
| @function_helper(helps=(np.isin, np.in1d)) # np.in1d deprecated in not NUMPY_LT_2_0. | ||
| def setcheckop(ar1, ar2, *args, **kwargs): | ||
| @function_helper # np.in1d deprecated in not NUMPY_LT_2_0. |
There was a problem hiding this comment.
Here, the comment is misleading, since this is for isin
| def setcheckop(ar1, ar2, *args, **kwargs): | ||
| @function_helper # np.in1d deprecated in not NUMPY_LT_2_0. | ||
| def isin(element, test_elements, *args, **kwargs): | ||
| # This tests whether ar1 is in ar2, so we should change the unit of |
There was a problem hiding this comment.
I guess here and below we might as well adjust the names to the new ones.
| args_helper = list(params_helper.items()) | ||
|
|
||
| pos_helper = 0 | ||
| for nt, pt in args_target: |
There was a problem hiding this comment.
With the for loop, you can just replace with params_target.items() and remove the above definition.
| params_helper = sig_helper.parameters | ||
|
|
||
| for kind in (POSITIONAL_ONLY, POSITIONAL_OR_KEYWORD): | ||
| args_target = self.get_param_group(params_helper, [POSITIONAL_ONLY]) |
There was a problem hiding this comment.
Here, you forgot to replace [POSITIONAL_ONLY] with [kind]!
| if (nhelper := len(args_helper)) > (ntarget := len(args_target)): | ||
| unknown: list[str] = args_helper[ntarget:] | ||
| raise AssertionError( | ||
| f"Found unknown {str(kind).lower().replace('_', '-')} parameter(s) " |
There was a problem hiding this comment.
For an error message, I'd not string-massage something that may change, i.e., just do unknown {kind} parameter(s)
I guess here the assert statement became just too unwieldy, right?
There was a problem hiding this comment.
I guess here the assert statement became just too unwieldy, right?
Correct ! that's exactly why I used raise AssertionError 😉
|
@mhvk Thank you so much for your careful review. I think I've addressed or answered all your comments now. |
mhvk
left a comment
There was a problem hiding this comment.
Super, looks all good. Thanks very much for creating this -- it should be a big help to keep things in sync.
|
Hmm do we have to backport this to make numpy-dev compat backports easier for 6.0.x? |
Good point. I think this is reasonably safe to backport, and it does fix one bug (new |
|
To me it would make sense to backport, but it's also fine not to. If you guys think there's a chance that backporting would be controversial, I don't think it's worth it. |
Description
Will close #15703
Opening as a draft with only the new tests. I'll address failures next.
ping @hamogu @mhvk