Skip to content

API: Cleaning numpy/__init__.py and main namespace - Part 4 [NEP 52] #24445

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

Merged
merged 9 commits into from
Sep 5, 2023

Conversation

mtsokol
Copy link
Member

@mtsokol mtsokol commented Aug 18, 2023

Follow-up PR after #24376 is merged. Can be merged independently.
Relevant issue: #24306.

Scope of the PR:

  • Deprecate row_stack (an alias for vstack) to be removed completely in 2.0
  • Deprecate trapz in favor of scipy.interpolate.trapezoid (scipy uses trapz implementation, therefore it must be moved there)
  • Deprecate in1d (instead use isin) and make in1d private in 2.0

@mtsokol mtsokol force-pushed the overhaul-of-main-namespace-part-4 branch from b812dfd to 35e072c Compare August 18, 2023 10:50
@mtsokol mtsokol changed the title Overhaul of main namespace part 4 API: Cleaning numpy/__init__.py and main namespace - Part 4 [NEP 52] Aug 18, 2023
@mtsokol mtsokol force-pushed the overhaul-of-main-namespace-part-4 branch 2 times, most recently from fea696e to f9fd36d Compare August 21, 2023 10:35
ksunden added a commit to ksunden/matplotlib that referenced this pull request Aug 21, 2023
Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great, just a couple comments.

@mtsokol mtsokol requested a review from ngoldbaum August 22, 2023 15:49
Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I see scipy/scipy#19100 got merged, are there other downstream PRs we should wait to get merged before this does?

@mtsokol
Copy link
Member Author

mtsokol commented Aug 22, 2023

LGTM. I see scipy/scipy#19100 got merged, are there other downstream PRs we should wait to get merged before this does?

There are still usages of them in SciPy and Pandas, I will create PRs shortly.

[EDIT] Done for Pandas, SciPy and scikit-learn. For matplotlib a draft PR was already created.

tylerjereddy added a commit to tylerjereddy/mdanalysis that referenced this pull request Aug 22, 2023
* replace deprecated `in1d` with `isin` calls per
numpy/numpy#24445, as part
of effort to remain NumPy `2.0` compliant

* the testsuite seems happy locally--if there are
any cases where `in1d` was potentially receiving
arrays with `ndim > 1`, we may want to add `ravel()`
to the outputs in these replacements just to be safe,
but I've assumed the testsuite has us covered

* for now, I've intentionally not adjusted the
docstring of our Cython `_in2d`, which refers
to `in1d`; seems less critical for now
@mtsokol mtsokol force-pushed the overhaul-of-main-namespace-part-4 branch from bebb3a2 to 732e6d5 Compare August 24, 2023 21:34
@tylerjereddy tylerjereddy added 30 - API 62 - Python API Changes or additions to the Python API. Mailing list should usually be notified. Numpy 2.0 API Changes labels Aug 25, 2023
Copy link
Contributor

@tylerjereddy tylerjereddy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff seems sensible to be me as well (there was some desire for a non-Quansight reviewer as well in last meeting).

I did wonder a little bit about whether it makes sense to delete the tests for i.e., trapz before the function is completely removed vs. suppressing the deprecation warnings on those tests until trapz disappears for good.

Downstream reception to the patches seems "ok" enough. I also opened a cross-listed PR to NumFOCUS project MDAnalysis and they seemed alright with it as well.

hmacdope pushed a commit to MDAnalysis/mdanalysis that referenced this pull request Aug 27, 2023
* MAINT: in1d -> isin

* replace deprecated `in1d` with `isin` calls per
numpy/numpy#24445, as part
of effort to remain NumPy `2.0` compliant

* the testsuite seems happy locally--if there are
any cases where `in1d` was potentially receiving
arrays with `ndim > 1`, we may want to add `ravel()`
to the outputs in these replacements just to be safe,
but I've assumed the testsuite has us covered

* for now, I've intentionally not adjusted the
docstring of our Cython `_in2d`, which refers
to `in1d`; seems less critical for now

* DOC: PR 4255 revisions

* add an appropriate `CHANGELOG` entry
per reviewer request

* Update package/CHANGELOG

---------

Co-authored-by: Oliver Beckstein <orbeckst@gmail.com>
@mtsokol mtsokol force-pushed the overhaul-of-main-namespace-part-4 branch from 48ca8f8 to 448dd0d Compare August 28, 2023 10:01
@mtsokol
Copy link
Member Author

mtsokol commented Aug 28, 2023

I did wonder a little bit about whether it makes sense to delete the tests for i.e., trapz before the function is completely removed vs. suppressing the deprecation warnings on those tests until trapz disappears for good.

@tylerjereddy I can reintroduce TestTrapz if needed - should I add them? The implementation with tests was already moved to SciPy.

@mtsokol mtsokol force-pushed the overhaul-of-main-namespace-part-4 branch from 0dfc32f to 41639e4 Compare August 28, 2023 10:33
@ngoldbaum
Copy link
Member

I think keeping the tests for deprecated code around is worthwhile, the marginal cost of running a unit test is low and it's possible superficially unrelated code changes could break deprecated functionality and it would be nice to be aware of that.

@mtsokol
Copy link
Member Author

mtsokol commented Aug 28, 2023

I think keeping the tests for deprecated code around is worthwhile, the marginal cost of running a unit test is low and it's possible superficially unrelated code changes could break deprecated functionality and it would be nice to be aware of that.

Makes sense to me - I reintroduced trapz tests with a deprecation warnings filter.

@mtsokol mtsokol requested a review from tylerjereddy August 29, 2023 11:43
@mtsokol mtsokol self-assigned this Aug 29, 2023
@mtsokol mtsokol force-pushed the overhaul-of-main-namespace-part-4 branch from 41f19fa to c60bdc6 Compare August 30, 2023 09:39
@mtsokol mtsokol force-pushed the overhaul-of-main-namespace-part-4 branch 2 times, most recently from 2bb6fcd to 4f5b772 Compare September 1, 2023 10:37
@rgommers rgommers added this to the 2.0.0 release milestone Sep 1, 2023
@rgommers
Copy link
Member

rgommers commented Sep 5, 2023

@mtsokol would you mind fixing the merge conflict?

@mtsokol mtsokol force-pushed the overhaul-of-main-namespace-part-4 branch from 4f5b772 to bf91c88 Compare September 5, 2023 19:03
@mtsokol
Copy link
Member Author

mtsokol commented Sep 5, 2023

@mtsokol would you mind fixing the merge conflict?

@rgommers Sure! Rebased.

Copy link
Member

@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this has been in the queue for 2 weeks, and it looks solid. In it goes, thanks @mtsokol!

@@ -4880,6 +4883,14 @@ def trapz(y, x=None, dx=1.0, axis=-1):
>>> np.trapz(a, axis=1)
array([2., 8.])
"""

# Deprecated in NumPy 2.0, 2023-08-18
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will affect a lot of analysis code... not just developers, but users.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, we did that same rename in scipy.integrate a few years ago, and got no complaints. This name is considered a slur, and that's an extra reason to get rid of it. We touched on this in the 2.0 dev call IIRC, and folks were in favor of names that are both more descriptive and more inclusive (cumsum & co too).

It's deprecated rather than outright removed here exactly because it's used quite a bit. So no code will actually break in the 2.0 release.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, didn't know it's a slur. Thanks for the clarification!

Copy link
Member

@rgommers rgommers Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither did I until scipy/scipy#12924.

@charris
Copy link
Member

charris commented Sep 7, 2023

Never heard/read it myself. Lots of things can become slurs when it is convenient.

BvB93 added a commit to BvB93/numpy that referenced this pull request Dec 21, 2023
BvB93 added a commit to BvB93/numpy that referenced this pull request Dec 21, 2023
@ntessore
Copy link
Contributor

ntessore commented Jan 9, 2024

I don't know which issue, or even venue, is appropriate for this, but can I please register the strongest possible objection to removing the trapezoidal rule entirely from numpy, and relying on scipy? It is such a fundamental and common operation, that it would be an immense downside having to depend on scipy just for this.

@rgommers
Copy link
Member

rgommers commented Jan 9, 2024

@ntessore could you please open a new issue instead? That way it's easier to discover and discuss. Expanding a little on the impact would be useful too (e.g., number of places it's used which don't already depend on SciPy).

bmwoodruff added a commit to bmwoodruff/numpy that referenced this pull request Jun 8, 2024
This PR adds back the links that were removed from `trapz`
in PR numpy#24445, finishing the migration to `trapezoid`
in PR numpy#25738. Currently, no web docs appear for `trapezoid`.
bmwoodruff added a commit to bmwoodruff/numpy that referenced this pull request Jun 8, 2024
This PR adds back the links that were removed from `trapz`
in PR numpy#24445, finishing the migration to `trapezoid`
in PR numpy#25738. Currently, no web docs appear for `trapezoid`.

[skip actions] [skip azp] [skip cirrus]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
30 - API 62 - Python API Changes or additions to the Python API. Mailing list should usually be notified. Numpy 2.0 API Changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants