-
-
Notifications
You must be signed in to change notification settings - Fork 11.8k
DEP: Deprecate numpy.fix #30098
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
base: main
Are you sure you want to change the base?
DEP: Deprecate numpy.fix #30098
Conversation
ngoldbaum
left a comment
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.
Thanks! Probably best to wait for someone else to weigh in before implementing my suggestion. Otherwise this all looks great.
|
It seems that my last error is due to this section: https://github.com/numpy/numpy/pull/30098/files#diff-6cdc3b490da76e0f287028f0c0fa780b24100106713a4216594f8d33d162fec6R36-R47 which is test data, but not picked up as tests, and a check complains about |
seberg
left a comment
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.
Nice, thanks. LGTM, two nits to change docs and maybe add to test_deprecations.py which would be nice (just to discover it, since this isn't C, I don't care too much about it).
| "ignore", | ||
| message="The function numpy.fix is deprecated in favor of numpy.trunc", | ||
| category=DeprecationWarning, | ||
| ) |
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.
@jorenham is there a proper way to call things that trigger deprecation warnings in the typing test data? this seems to run afoul of the test that checks the codebase for warning filters.
We could also patch that test to skip the typing test data. Maybe it doesn't matter if the typing tests trigger deprecation warnings? I don't actually know.
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.
Completely fine to change ignore it in those tests in principle, I think. The only reason for the filter in other tests was that it is nicer to have another solution (e.g. pytest.warns or @pytest.filterwarnings).
(The test comes from a different time and age and the original purpose is moot, now we just have nicer spellings :))
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 am unsure what this means. Do I get rid of these calls completely or should I look at how to change the test script? I can do the latter, but that seems like a separate PR to me, right?
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.
@jorenham is there a proper way to call things that trigger deprecation warnings in the typing test data? this seems to run afoul of the test that checks the codebase for warning filters.
We could also patch that test to skip the typing test data. Maybe it doesn't matter if the typing tests trigger deprecation warnings? I don't actually know.
Yea there is the typing_extensions.deprecated decorator that can be used in the stubs. It can be applied to classes, functions, or individual overloads. See for example
numpy/numpy/_core/arrayprint.pyi
Lines 96 to 188 in d8eb225
| # public numpy export | |
| @overload # no style | |
| def array2string( | |
| a: NDArray[Any], | |
| max_line_width: int | None = None, | |
| precision: SupportsIndex | None = None, | |
| suppress_small: bool | None = None, | |
| separator: str = " ", | |
| prefix: str = "", | |
| style: _NoValueType = ..., | |
| formatter: _FormatDict | None = None, | |
| threshold: int | None = None, | |
| edgeitems: int | None = None, | |
| sign: _Sign | None = None, | |
| floatmode: _FloatMode | None = None, | |
| suffix: str = "", | |
| *, | |
| legacy: _Legacy | None = None, | |
| ) -> str: ... | |
| @overload # style=<given> (positional), legacy="1.13" | |
| def array2string( | |
| a: NDArray[Any], | |
| max_line_width: int | None, | |
| precision: SupportsIndex | None, | |
| suppress_small: bool | None, | |
| separator: str, | |
| prefix: str, | |
| style: _ReprFunc, | |
| formatter: _FormatDict | None = None, | |
| threshold: int | None = None, | |
| edgeitems: int | None = None, | |
| sign: _Sign | None = None, | |
| floatmode: _FloatMode | None = None, | |
| suffix: str = "", | |
| *, | |
| legacy: Literal["1.13"], | |
| ) -> str: ... | |
| @overload # style=<given> (keyword), legacy="1.13" | |
| def array2string( | |
| a: NDArray[Any], | |
| max_line_width: int | None = None, | |
| precision: SupportsIndex | None = None, | |
| suppress_small: bool | None = None, | |
| separator: str = " ", | |
| prefix: str = "", | |
| *, | |
| style: _ReprFunc, | |
| formatter: _FormatDict | None = None, | |
| threshold: int | None = None, | |
| edgeitems: int | None = None, | |
| sign: _Sign | None = None, | |
| floatmode: _FloatMode | None = None, | |
| suffix: str = "", | |
| legacy: Literal["1.13"], | |
| ) -> str: ... | |
| @overload # style=<given> (positional), legacy!="1.13" | |
| @deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode") | |
| def array2string( | |
| a: NDArray[Any], | |
| max_line_width: int | None, | |
| precision: SupportsIndex | None, | |
| suppress_small: bool | None, | |
| separator: str, | |
| prefix: str, | |
| style: _ReprFunc, | |
| formatter: _FormatDict | None = None, | |
| threshold: int | None = None, | |
| edgeitems: int | None = None, | |
| sign: _Sign | None = None, | |
| floatmode: _FloatMode | None = None, | |
| suffix: str = "", | |
| *, | |
| legacy: _LegacyNoStyle | None = None, | |
| ) -> str: ... | |
| @overload # style=<given> (keyword), legacy="1.13" | |
| @deprecated("'style' argument is deprecated and no longer functional except in 1.13 'legacy' mode") | |
| def array2string( | |
| a: NDArray[Any], | |
| max_line_width: int | None = None, | |
| precision: SupportsIndex | None = None, | |
| suppress_small: bool | None = None, | |
| separator: str = " ", | |
| prefix: str = "", | |
| *, | |
| style: _ReprFunc, | |
| formatter: _FormatDict | None = None, | |
| threshold: int | None = None, | |
| edgeitems: int | None = None, | |
| sign: _Sign | None = None, | |
| floatmode: _FloatMode | None = None, | |
| suffix: str = "", | |
| legacy: _LegacyNoStyle | None = None, | |
| ) -> str: ... |
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.
Ah, I see, that's what's missing. This PR also needs to update the type stubs for np.fix:
numpy/numpy/lib/_ufunclike_impl.pyi
Lines 16 to 35 in d8eb225
| @overload | |
| def fix( # type: ignore[misc] | |
| x: _FloatLike_co, | |
| out: None = None, | |
| ) -> floating: ... | |
| @overload | |
| def fix( | |
| x: _ArrayLikeFloat_co, | |
| out: None = None, | |
| ) -> NDArray[floating]: ... | |
| @overload | |
| def fix( | |
| x: _ArrayLikeObject_co, | |
| out: None = None, | |
| ) -> NDArray[object_]: ... | |
| @overload | |
| def fix( | |
| x: _ArrayLikeFloat_co | _ArrayLikeObject_co, | |
| out: _ArrayT, | |
| ) -> _ArrayT: ... |
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.
If I use that decorator locally (after importing of course 🤦 ), I still seem to be getting the errors on the deprecation message. So I suppose the question remains whether the checks should be dropped from numpy/typing/tests/data/pass/ufunclike.py and numpy/typing/tests/data/reveal/ufunclike.pyi?
|
So, it seems like the easiest way to deal with this deprecation is to
Both of these mean losing fidelity, but I’m not well-versed enough in the codebase to propose alternatives, unfortunately. |
You could also smack a |
This comment has been minimized.
This comment has been minimized.
I might be misunderstanding, but doesn’t that then defeat the prupose of the tests? |
it would only suppress the |
rgommers
left a comment
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 deprecation looks justified (despite us not removing this for 2.0 because of concerns of widespread usage), but a blocking comment for merge with a few comments:
- This should be proposed on the NumPy mailing list before it can proceed, like all deprecations.
- This should not be merged this late in a release cycle, so please make it 2.5.0 not 2.4.0
- This cannot be merged before downstream users of our nightlies have been updated. E.g., I see usages in scikit-image and in PyWavelets. PRs to replace those usages would be nice to help this move along.
Looks like that has the same issue, since now the assertion error is: |
Fair enough - I cleared the 2.4.0 milestone. @hellerve - if you're interested, it might be a fun exercise to contribute to a bunch of other popular projects as well if you could take a shot at doing the migration in a few popular packages. In addition to PyWavelets and scikit-image, which both looks like they use It also looks like It looks like SciPy and matplotlib don't use it, as far as I can see. |
IMO it's fine to add an exception to the test that checks for warning filters to ignore code in the numpy/numpy/tests/test_warnings.py Lines 67 to 74 in 1e424da
|
I feel totally up to it (more than for the mailing list proposal, anyway 😅). I’ll take a look and start contributing PRs. Is there a script you use to check for usages or just go through a set of known repositories and check? |
As part of this PR or a different one (since it’s more or less unconcerned with this particular deprecation)? |
I just search known downstream projects first to get a sense, and then I may check what https://github.com/search?type=code says. |
Doing it in this one is fine. I doubt it will come up again before this is merged. |
|
Alright, looks like we got the tests green, and I also adjusted the code comments to make the target |
|
I did an (admittedly small) amount of digging for references. I unfortunately don’t have good insight into what repositories are considered "important", and Github search limits me to 5 largely unordered pages of results. I did submit 4 PRs just now, among others to pywt and scikit-image. I also checked a few others but couldn’t find much. (No guarantees, though) |
|
It looks like there are also a couple other uses in pandas that can be straightforwardly updated, if you want another easy contribution: There's another use in the tests that's testing explicitly for support of |
Contributed a PR there too. |
|
Thanks @hellerve, it's cool to see that you updated things there! There was a small unintended regression in |
|
I’ll solve the merge conflicts once #30168 has also been merged (I’m assuming it will be merged before this PR is even considered). |
|
Needs rebase. #30168 is in. |
…gs in np.fix tests
d9398a1 to
44b7c57
Compare
|
@charris Thanks for the heads-up! Done! |
This PR fixes #30096 (especially its follow-up comments) by deprecating
numpy.fix.Cheers