-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
NEP: Making details of np.core
private
#11924
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
Conversation
b2f5cac
to
51b3dc3
Compare
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.*``. |
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 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.
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.
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
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.
Updated the text with this example
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. |
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.
Maybe a lot less work: move np.core
to np._core
(and and import warnings for np.core
)
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 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.
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.
@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.
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 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.
eb55387
to
563f5c4
Compare
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. |
This is a NEP proposal, I think we should either move it forward as a draft NEP for wider disucssion or close the PR. |
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. |
This NEP is still not merged to draft state, and still looking for someone to move it forward |
np.core
privatenp.core
private
@@ -0,0 +1,165 @@ | |||
============================================== | |||
NEP 23 — Making details of ``np.core`` private | |||
============================================== |
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.
Number needs updating to 46. Also needs a new file name.
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.
47 now
I'm inclined to put this in for discussion, but needs updating. |
close/reopen. |
'shape_base', | ||
'umath'] | ||
|
||
The publicness of this API surface is contagious - in principle, |
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.
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``. |
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.
without risking breaking someone using ``np.core.numeric.array``. | |
without risking breaking code importing ``np.core.numeric.array``. |
relying on implementation details. | ||
|
||
|
||
Implementation |
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.
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.*``. |
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.
Not sure what "until we lift these members to np.core" means here. They should probably be lifted to numpy.lib
?
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 ..... |
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. |
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:
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. |
+1 for this
This was the case for the way we just did things in SciPy (adding back a
Are there actually any that should be public? IIRC |
Yes, I agree they are niche, but I suspect they exist. But yes, even OK to deprecated and see who shouts, probably. |
At least one, already mentioned in the NEP:
The comments in the thread suggest eventually moving the function to a "more public" namespace, e.g. FWIW, I also noticed the cupy issue cupy/cupy#4522, and I see that dask uses Update: astropy also uses |
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