8000 Duplicate entries in np.__all__ · Issue #10198 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Duplicate entries in np.__all__ #10198

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

Closed
eric-wieser opened this issue Dec 11, 2017 · 1 comment · Fixed by #20284
Closed

Duplicate entries in np.__all__ #10198

eric-wieser opened this issue Dec 11, 2017 · 1 comment · Fixed by #20284

Comments

@eric-wieser
Copy link
Member
eric-wieser commented Dec 11, 2017

These might be symptomatic of having two implementations, where the one that is actually used is determined by the import order (not good).

>>> import collections
>>> {k: v for k, v in collections.Counter(np.__all__).items() if v > 1}
{'alen': 2,
 'all': 2,
 'alltrue': 2,
 'amax': 2,
 'amin': 2,
 'any': 2,
 'argmax': 2,
 'argmin': 2,
 'argpartition': 2,
 'argsort': 2,
 'around': 2,
 'choose': 2,
 'clip': 2,
 'compress': 2,
 'cumprod': 2,
 'cumproduct': 2,
 'cumsum': 2,
 'diagonal': 2,
 'mean': 2,
 'ndim': 2,
 'nonzero': 2,
 'partition': 2,
 'prod': 2,
 'product': 2,
 'ptp': 2,
 'put': 2,
 'ravel': 2,
 'repeat': 2,
 'reshape': 2,
 'resize': 2,
 'round_': 2,
 'searchsorted': 2,
 'shape': 2,
 'size': 2,
 'sometrue': 2,
 'sort': 2,
 'squeeze': 2,
 'std': 2,
 'sum': 2,
 'swapaxes': 2,
 'take': 2,
 'trace': 2,
 'transpose': 2,
 'var': 2,
 'issubdtype': 2}
@WarrenWeckesser
Copy link
Member

All those names except issubdtype are duplicated because of these two lines in numpy/core/__init__.py:

__all__ += numeric.__all__
__all__ += fromnumeric.__all__

numeric.py already imports everything from fromnumeric.py and puts it in numeric.__all__, so we can remove all the duplicates except issubdtype by removing the redundant line from core/__init__.py.

The duplication of issubdtype occurs because it is exposed as both numpy.core.issubdtype and numpy.lib.issubdtype:

  • issubdtype is defined in core/numerictypes.py, and is included in numerictypes.__all__.
  • core/numeric.py adds the names from core.numerictypes.__all__ to its __all__ list, and core/__init__.py adds numeric.__all__ to its __all__ list.
  • lib/utils.py imports issubclass_, issubsctype, and issubdtype from numpy.core.numerictypes and includes them in its __all__ list.
  • lib/__init__.py adds utils.__all__ to its __all__ list.
  • In the top-level __init__.py, core.__all__ and lib.__all__ are added to the numpy __all__ list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
0