Skip to content
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

NEP: Making details of np.core private #11924

Closed
wants to merge 3 commits into from

Conversation

eric-wieser
Copy link
Member

This is a rough draft of what I had in mind in the comments of #11909.

I don't think I'll have the energy to champion this, and would greatly appreciate if someone else could take over from me

Backward compatibility
----------------------

In some cases, there may be members at ``np.core.*.*`` which we intended to be public-facing. Users of these will receive ``DeprecationWarning``s until we lift these members to ``np.core.*``.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think those exist. The whole np.core was never intended to be public (and arguably it isn't, missing underscores or not), so submodules of np.core certainly weren't intended to be public.

Copy link
Member Author

Choose a reason for hiding this comment

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

As an example, np.core.numeric.normalize_axis_index never made it to the top level.

I'd consider moving that to np.core.normalize_axis_index - I think it's perhaps valuable to have a separation between "apis a user would use" and "apis a library cooperating with numpy would use" - np.* vs np.core.* sounds like a reasonable line to draw

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the text with this example

@rgommers
Copy link
Member

I proposed something similar for scipy in 2011: https://mail.python.org/pipermail/scipy-dev/2011-June/016337.html. Didn't happen in the end.


The proposal here is to:

* Make all of the existing modules within `np.core` private, adding a leading underscore to their names.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a lot less work: move np.core to np._core (and and import warnings for np.core)

Copy link
Member Author

@eric-wieser eric-wieser Sep 10, 2018

Choose a reason for hiding this comment

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

If we want to continue supporting (with deprecation warnings) from numpy.core.numeric import something, this is (marginally) more work, not less - you still need a dummy module for every submodule of core.

Copy link
Member

Choose a reason for hiding this comment

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

@rgommers A similar thought occurred to me. This is beginning to sound like the evolution of the numpy.testing package where we ended up with a couple of stub modules and _private. A clear statement of intent and justification would be good to have.

Copy link
Member

Choose a reason for hiding this comment

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

I see that there is a statement of intent. Maybe we can expand this to a discussion of what we would like NumPy to look like in the long term.

@ahaldane
Copy link
Member

I think I'm +1 on this.

A clearly demarcated public/private api is a good thing. While maintaining back-compat is very important, so is dev freedom to change things, and sometimes it seems like the pendulum has swung to far to the former. It's not good to unnecessarly trap numpy into back-compat corners, as seems to have happened with these core modules.

The old modules can all be soft-deprecated, so no one's code will break except that they get deprecation warnings.

@mattip
Copy link
Member

mattip commented Dec 5, 2019

This is a NEP proposal, I think we should either move it forward as a draft NEP for wider disucssion or close the PR.

@rgommers
Copy link
Member

rgommers commented Dec 5, 2019

This is a good idea, so please don't close it.

Move forward: @eric-wieser asked for a volunteer. I think this NEP is probably higher prio than most PRs that are open.

@seberg seberg added the Priority: high High priority, also add milestones for urgent issues label Jan 17, 2020
@mattip
Copy link
Member

mattip commented Jul 13, 2020

This NEP is still not merged to draft state, and still looking for someone to move it forward

@charris charris changed the title WIP/NEP: Making details of np.core private NEP: Making details of np.core private Dec 18, 2020
@charris charris removed the 25 - WIP label Dec 18, 2020
@@ -0,0 +1,165 @@
==============================================
NEP 23 — Making details of ``np.core`` private
==============================================
Copy link
Member

Choose a reason for hiding this comment

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

Number needs updating to 46. Also needs a new file name.

Copy link
Member

Choose a reason for hiding this comment

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

47 now

@charris
Copy link
Member

charris commented Dec 18, 2020

I'm inclined to put this in for discussion, but needs updating.

@charris
Copy link
Member

charris commented Dec 18, 2020

close/reopen.

@charris charris closed this Dec 18, 2020
@charris charris reopened this Dec 18, 2020
'shape_base',
'umath']

The publicness of this API surface is contagious - in principle,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The publicness of this API surface is contagious - in principle,
`np.core` and its submodules greatly increase the public API surface of NumPy—in principle, for example,


This is problematic - it means that if ``numeric.py`` contains ``from
numpy.core.multiarray import array``, then we can never remove that line
without risking breaking someone using ``np.core.numeric.array``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
without risking breaking someone using ``np.core.numeric.array``.
without risking breaking code importing ``np.core.numeric.array``.

relying on implementation details.


Implementation
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe the implementation code should be left to a PR, that can be linked in. My take was that the Implementation sections are for discussing implementation decisions, but not code.

somewhat public-facing. An example of such a function is
`numpy.core.numeric.normalize_axis_index`, which downstream libraries are
starting to use to validate axis arguments. Users of these functions will
receive ``DeprecationWarning``s until we lift these members to ``np.core.*``.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what "until we lift these members to np.core" means here. They should probably be lifted to numpy.lib?

@rgommers
Copy link
Member

I forgot about this NEP. Nice timing to comment on it @stefanv. I'll at least link to it from my upcoming NEP about the array API standard. I'd also be interested to push this forward, just a matter of finding the time .....

@rgommers
Copy link
Member

Let me also link https://github.com/numpy/numpy/commits/master/numpy/tests/test_public_api.py, which has all the relevant public/private/in-between parts listed.

Base automatically changed from master to main March 4, 2021 02:04
@InessaPawson InessaPawson added the triage review Issue/PR to be discussed at the next triage meeting label Dec 13, 2021
@seberg
Copy link
Member

seberg commented Dec 15, 2021

We discussed this today, and were landing a bit on "not really a big urgency". This seems obviously a good idea, I personally do not even feel we need a NEP, unless there is a surprising amount of downstream breakage (but it cannot hurt).

The main concerns are:

  • Where to put the symbols only available through core, this needs a concrete proposal to decide on.
  • There may be quite a few PRs that have merge conflict.

Neither seem like big road blocks, and DeprecationWarnings can linger for a while (or even only be added after big downstream packages are fixed).

IMO, the main point here is to do the work, and if we want finish up the NEP in no particular order.

@rgommers
Copy link
Member

+1 for this

There may be quite a few PRs that have merge conflict.

This was the case for the way we just did things in SciPy (adding back a core.py with a __getattr__ and raising suitable deprecation warnings), but scikit-learn dynamically generates core.py and then there's no merge conflicts at all - Git will understand the git mv action.

Where to put the symbols only available through core, this needs a concrete proposal to decide on.

Are there actually any that should be public? IIRC numpy.core submodules are not in the html docs, so there may not be any objects of interest? There's only very few examples given in the draft here, and they're pretty niche.

@seberg
Copy link
Member

seberg commented Dec 15, 2021

There's only very few examples given in the draft here, and they're pretty niche.

Yes, I agree they are niche, but I suspect they exist. But yes, even OK to deprecated and see who shouts, probably.

@WarrenWeckesser
Copy link
Member

WarrenWeckesser commented Dec 15, 2021

Are there actually any that should be public?

At least one, already mentioned in the NEP: normalize_axis_index from numpy.core.multiarray (also in numpy.core.numeric). We use this in SciPy . I asked about this on the mailing list (note that I initially referred to the wrong namespace), and in that thread, @eric-wieser said

When I added this function, it was always my intent for it to be consumed
by downstream packages, but as Sebastian remarks, it wasn't really
desirable to put it in the top-level namespace.

I think I would be reasonably happy to make the guarantee that it would not
be removed (or more likely, moved) without a lengthy deprecation cycle.

The comments in the thread suggest eventually moving the function to a "more public" namespace, e.g. numpy.lib, but not necessarily the top-level namespace.

FWIW, I also noticed the cupy issue cupy/cupy#4522, and I see that dask uses normalize_axis_index and normalize_axis_tuple in the file numpy_compat.py, both imported from numpy.core.numeric.

Update: astropy also uses normalize_axis_index, and normalize_axis_tuple (in a compatibility function that will go away when they no longer support numpy less than 1.18). And numba has a recent pull request to add support for numpy.core.multiarray.normalize_axis_index.

@InessaPawson InessaPawson removed the triage review Issue/PR to be discussed at the next triage meeting label Jan 12, 2022
@charris charris added the 52 - Inactive Pending author response label Apr 6, 2022
@charris charris closed this Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
52 - Inactive Pending author response component: NEP Priority: high High priority, also add milestones for urgent issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants