-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
API: Cleaning numpy/__init__.py and main namespace - Part 2 [NEP 52] #24357
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
API: Cleaning numpy/__init__.py and main namespace - Part 2 [NEP 52] #24357
Conversation
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.
Getting rid of import *
will be useful. The last commit looks close to ready after a rebase. Note that there are some more __all__.remove
usages in __init__.py
that can be removed (e.g. for issubdtype
, long
, unicode
).
fee0b86
to
ed17e34
Compare
ed17e34
to
09dad16
Compare
64a4f4c
to
110b953
Compare
Hi @rgommers! I pushed another batch of changes addressing review comments. Currently, in this PR:
[EDIT 9.08.2023] Changelog is reported in PR's description/top message |
I'd probably change the usages in the tests to import these constants from |
Great to see |
e42af77
to
9bbae54
Compare
Hi @rgommers @ngoldbaum, This PR is ready for a review - some CI staged failed due to the fact that Pandas uses This work's primary purpose is to remove |
Tests are failing because pandas fails to import in the doctests build. Will be fixed once https://github.com/pandas-dev/pandas/pull/54468/files is merged and a new pandas wheel gets uploaded. |
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.
Just one comment that should be deleted I think, otherwise LGTM!
Looks like we're in luck; pandas uploads nightlies frequently and it's already fixed, the job passed. |
39e813b
to
fbc386b
Compare
fbc386b
to
04dd24d
Compare
This follows the upstream NumPy deprecation of these names (numpy/numpy#24357). PiperOrigin-RevId: 555530455
This follows the upstream NumPy deprecation of these names (numpy/numpy#24357). PiperOrigin-RevId: 555530455
This follows the upstream NumPy deprecation of these names (numpy/numpy#24357). PiperOrigin-RevId: 555530455
This follows the upstream NumPy deprecation of these names (numpy/numpy#24357). PiperOrigin-RevId: 555548986
I'm not sure about the use of The one thing I did notice is that the list of public symbols still isn't 100% correct for submodule names. From https://numpy.org/neps/nep-0052-python-api-cleanup.html#cleaning-up-the-submodule-structure I think |
@rgommers In this PR I wanted to mostly focus on removing |
This looks good to me now: >>> l = np.__dir__()
>>> l2 = [str(s) for s in np.load('../bldnumpy/main.npy')] # __dir__ from current `main`
>>> set(l2) - set(l)
{'PZERO', 'add_newdoc', 'MAY_SHARE_EXACT', 'ALLOW_THREADS', 'UFUNC_BUFSIZE_DEFAULT', 'CLIP', 'RAISE', 'NAN', 'UFUNC_PYVALS_NAME', 'NINF', 'FPE_OVERFLOW', 'version', 'FPE_INVALID', 'FPE_UNDERFLOW', '_UFUNC_API', 'MAXDIMS', 'WRAP', 'MAY_SHARE_BOUNDS', 'add_docstring', 'NZERO', 'add_newdoc_ufunc', 'FPE_DIVIDEBYZERO', 'PINF', '_add_newdoc_ufunc', 'FLOATING_POINT_SUPPORT', 'BUFSIZE'}
>>> set(l) - set(l2)
{'f2py', 'array_api', 'typing', 'distutils', '__numpy_submodules__'}
>>> {s for s in set(np.__dir__()) - set(np.__all__)}
{'__getattr__', '__package__', '_NoValue', '_pyinstaller_hooks_dir', '__builtins__', '__spec__', '_typing', '__loader__', '__git_version__', '__config__', '__all__', '_globals', '__path__', '__doc__', '__NUMPY_SETUP__', '__dir__', '_distributor_init', '__file__', '_pytesttester', '_version', '__future_scalars__', '__cached__', '_utils', '_type_info', '_int_extended_msg', '__name__', '__former_attrs__', '_CopyMode', '_msg', '__numpy_submodules__', '_mat', '_specific_msg', '_version_meson'}
>>> {s for s in set(np.__dir__()) - set(np.__all__) if not s.startswith('_')}
set()
>>> {s for s in set(np.__all__) - set(np.__dir__()) if not s.startswith('_')}
set() |
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 looks good to me now. The added test to ensure that __dir__()
and __all__
contain the same public members is nice and will be useful going forward.
One last question about Arrayterator
, since that's a change to numpy.lib
that would have been nicer to avoid.
All the removed items from the main namespace here seem uncontroversial, and you've checked that none of them are used in Pandas, scikit-learn, SciPy, Matplotlib, JAX, CuPy et al. anymore (or, in most cases, never were used to begin with).
@rgommers One last thing - I double checked other libraries that are impacted and I noticed that SciPy uses |
Thanks Mateusz! I know this is fiddly, but in the long run it'll be worth it to have PRs that are independent and scoped to a well-defined purpose. I'll look at merging this once CI is happy. |
@rgommers Looks that CI completed. I did one more round checking usages of removed items in other libraries and found one in SciPy that I missed: scipy/scipy#19045 |
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 @mtsokol, all LGTM now. I ran out of time with the many other NumPy changes; will leave this open right now just in case someone else wants to have a look. I'll plan to merge it tomorrow.
In it went - thanks again Mateusz! |
This PR is a second batch of NumPy main namespace changes.
First merged part available here: #24316.
Scope of PR
Removed
from ... import *
from the main namespacenumpy/__init__.py
, which is the main purpose of this PR. Changes listed below are direct consequences of this modification. A full main namespace cleanup will be a separate PR.Made submodules are imported lazily
Removed a subset of names from the top namespace listed in the “remove” section in
ENH: Overhaul of NumPy main namespace [NEP 52] #24306 (comment). The current changelog:
FLOATING_POINT_SUPPORT
FPE_DIVIDEBYZERO
FPE_INVALID
FPE_OVERFLOW
FPE_UNDERFLOW
NINF
,NZERO
,PINF
,PZERO
UFUNC_BUFSIZE_DEFAULT
UFUNC_PYVALS_NAME
CLIP
,WRAP
,RAISE
BUFSIZE
ALLOW_THREADS
MAXDIMS
MAY_SHARE_EXACT
,MAY_SHARE_BOUNDS
add_newdoc
,add_docstring
,add_newdoc_ufunc
Removed
issubdtype
fromlib
as it's already imported fromcore
(top__init__.py
had to remove one of them)Moved
add_newdoc
,add_docstring
,add_newdoc_ufunc
tests tocore
, as this module hosts their implementationsRemoved
Arrayterator
fromlib
's__all__