Repository navigation
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 |
|
@nstarman I just realized that we could skip the deprecation cycle for private methods. Do you agree ? |
|
Yes! Only public functions. |
|
I just included my test after I did some refactoring (probably a mistake) and now they are failing locally. I still pushed to see if the bug also shows in CI, but clearly this needs some more tinkering. |
88fbdb6 to
d6efe8d
Compare
|
Almost there. I collapsed my branch after I made sure all lights were green. Before I undraft this, I'd like to give @nstarman priority for reviewing since this is based off his work and largely co-authored. |
neutrinoceros
left a comment
There was a problem hiding this comment.
Leaving myself a comment from my phone.
| @deprecated_keywords("z", since="7.0") | ||
| def scale_factor(self, z): |
There was a problem hiding this comment.
Haven't looked through the C-code yet, but does @deprecated_keywords map to the positions? As in, can this be made positional-only now? And then we remove the decorator later, to complete the deprecation?
There was a problem hiding this comment.
It doesn't. Maybe it's possible but I don't know the C API well enough to see how it could be implemented.
There was a problem hiding this comment.
Actually I do think it's feasible, but it's a trade-of for where we put complexity: it would certainly make the C extension more complex and I'm already pushing my own limit there so I'm not confident that I could build this feature without hurting robustness and readability. How about I give it a try as a follow up task ?
There was a problem hiding this comment.
I think that's totally reasonable! And thanks again for taking the lead on this!
Having the parameters be positional-only at the undecorated Python function level is an improvement, but to the user there is no difference, so the PR as written is great 👍.
There was a problem hiding this comment.
dully noted !
There was a problem hiding this comment.
In hindsight and given the complaints this PR got for introducing a hard-to-maintain C extension, I'm not sure it's worth pushing it any further without a clear need to.
|
I'm on holidays this week, but FWIW happy with the general idea. |
d6efe8d to
254fa3b
Compare
nstarman
left a comment
There was a problem hiding this comment.
Thanks @neutrinoceros! This looks great. I would love it if someone else also reviewed the C-code, as I'm much less conversant in C-to-Python.
| # F = TypeVar("F", bound=Callable[..., Any]) | ||
| F = Callable[..., Any] |
There was a problem hiding this comment.
I think you can do
| # F = TypeVar("F", bound=Callable[..., Any]) | |
| F = Callable[..., Any] | |
| _F = TypeVar("_F", bound=Callable[..., Any]) |
| from inspect import signature | ||
| from typing import Any | ||
|
|
||
| from ._signature_deprecations import _depr_kws_wrap |
There was a problem hiding this comment.
I am not familiar with cosmology code base, so please explain to me why deprecating z in cosmology needs C extension in utils. Thanks!
There was a problem hiding this comment.
Ah, I just saw #15859 (comment) . Performance boost is always welcome but I am afraid this C code would also make the decorator hard to maintain going forward. I will put this on queue to review.
There was a problem hiding this comment.
Oh, so this boost is only for a very specific case. And I feel like the new function (ignoring performance) duplicated something deprecated_renamed_argument can already do. I need to ponder.
Even if we decide to keep this as-is, license for https://pypi.org/project/positional-defaults/ would need to be included in https://github.com/astropy/astropy/tree/main/licenses
There was a problem hiding this comment.
Also the new function is technically new API, so might also need a change log for utils.
There was a problem hiding this comment.
And I feel like the new function (ignoring performance) duplicated something
deprecated_renamed_argumentcan already do.
I don't think that's the case. deprecated_renamed_argument only works if a keyword argument is still allowed, albeit under a new name, while deprecated_keyword forces the user to stop using the argument as keyword.
I am afraid this C code would also make the decorator hard to maintain going forward
Also the new function is technically new API
Good points. We don't actually need to make it public API. Maybe we can keep it private for now and see where it goes ? If it's not used at all after this deprecation cycle is concluded we can just get rid of this C extension altogether ?
Even if we decide to keep this as-is, license for pypi.org/project/positional-defaults would need to be included in main/licenses
Thanks !
There was a problem hiding this comment.
Good points. We don't actually need to make it public API
Agreed. Let's make it private. If @mhvk or @pllim prefers, we can also move it into cosmology. Though looking around Astropy I would recommend other maintainers avail themselves of this useful utility and consider making some required arguments positional-only.
4c2a5cc to
7588291
Compare
|
Definitely from the sidelines, but this seems an inordinate amount of extra code for what essentially is beautification of the code. After all, nothing is stopping people now from using a positional argument; all this does is stop people from using |
|
@nstarman do you want to reply here ? |
Yes! There are a few motivating factors behind this change:
All of the functions that are being updated take the redshift as their first (or first 2) required arguments. The meaning of the function is contextually clear even without the variable names (which are still visible even when positional-only and further clarify meaning). So given that
Yes plz. Last, as more a general philosophical point. These methods were written before positional-only arguments were a thing in Python. So when written they had to be positional-or-keyword. Once PEP 570 was implemented it is good to look at the code and ask where PEP 570 is relevant and can improve our API. This is one such place. We can and should improve the API in ways big and small. The reason this PR is heavy is because we are also dedicated to long-term support and smooth transitions. This PR could be very lightweight if we didn't offer a performant deprecation period! As a possible alternative, we could move the decorator into |
|
Re: decorator -- If you think the performance is irrelevant outside of this narrow set of code, then it is best to keep it super private and then remove as @nstarman suggested. Otherwise, I fear it could have package-wide implication. And I think the decorator speed-up is best done as a separate PR. And should be used more widely in other subpackages as well to be consistent. |
|
Ok, let's make the decorator a private asset of
To be clear, are you suggesting I re-implement the decorator in Python only for the sake of delaying the more painful review ?
Sorry I don't get what you mean here. |
006a163 to
bf51a29
Compare
No, I mean, if you want to keep the C-extension and have it exposed via
I am uneasy with this but it would be much less controversial. Maybe we need to step back and rethink this whole thing. Let's look at this: @deprecated_keywords("z", since="7.0")
def scale_factor(self, z):
# ...The signature has always suggests Can we just do this and be done with it? def scale_factor(self, z, /):
# ...In the change log, we can say like "ooops you been using it in a way we didn't mean to support, you cannot do that anymore in 7.0" and that is probably okay because it is a major release and breaking change is allowed. |
|
In the absence of a clear deprecation path, biting the bullet would make sense to me, but |
|
How many users are we antagonizing? If it is just one or two, I will take that risk. I will even open a PR in their repos. |
|
Also if performance is really such a concern to the point you need C-extension for a decorator, biting bullet with |
No idea. Which is precisely why I'd err on the side of caution and avoid taking a risk. I also assume that a majority of our users wouldn't provide feedback or make their code public, so I would rather not create a precedent where we could have avoided immediate breakage for them and didn't. |
|
Again from the sidelines - while I would probably still not bother myself, the arguments for making it positional-only (eventually) are reasonable and now that one has done the work, it is perhaps a bit silly to not implement this. I think making it a cosmology-internal function is the way to go - if we need it elsewhere, we can still move it, but this way it is clear the whole stuff can go once the deprecation period is over. Indeed, would be good to open an issue now for 8.0(?) to remind us to remove all of it. |
|
Here you go: #16614 |
Surprisingly a lot. https://github.com/search?q=distance%28z%3D&type=code is a quick search on just a small slice of our API.
Why don't we get this into "array" and/or "kernel" in astropy/astropy/convolution/convolve.py Lines 124 to 127 in 5519605 "obj" in astropy/astropy/coordinates/sky_coordinate.py Line 511 in 5519605 "data" in astropy/astropy/io/registry/core.py Line 343 in 5519605 "inputs" in astropy/astropy/modeling/core.py Line 1076 in 5519605 "val" in astropy/astropy/nddata/bitmask.py Line 61 in 5519605 "a" in astropy/astropy/stats/histogram.py Line 22 in 5519605 "table1", "table2" in astropy/astropy/table/operations.py Line 471 in 5519605 "other" in Line 1251 in 5519605 "array" in astropy/astropy/timeseries/downsample.py Line 16 in 5519605 etc. |
pllim
left a comment
There was a problem hiding this comment.
Since I have been outvoted, I'll let Nathaniel or Marten to have one last look and merge. Just asking you to remove the diff from utils. Thanks!
Signed-off-by: nstarman <[email protected]>
bf51a29 to
7d73b01
Compare
7d73b01 to
d2661dd
Compare
|
done. I've also squashed my commits together (but left @nstarman's alone) |
There was a problem hiding this comment.
I just want to make @adrn aware of yet another utils module. (Inside joke...)
|
@nstarman is this ready to go ? |
|
Yes! I hadn't notice that you'd moved the C code into |
|
Thanks @neutrinoceros ! This turned out nicely. And the timing arguments show the overhead is as small as can be reasonably accomplished for adding another function call to the stack. |
|
I haven't thought about using positional-only function arguments in |
* DEPR: deprecate passing redshift (`z`) as a keyword argument Signed-off-by: nstarman <[email protected]> Co-authored-by: nstarman <[email protected]>
Description
This is the continuation (and revival) of @nstarman's work in #15859. See that PR for motivation.
It is still a work in progress as I haven't applied my decorator anywhere yet. I'm opening as a draft to check for compilation and other installation errors on all platforms.Close #15859
TODO: