8000 DOC: allow np as a module for documentation by mattip · Pull Request #11344 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

DOC: allow np as a module for documentation #11344

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
wants to merge 1 commit into from

Conversation

mattip
Copy link
Member
@mattip mattip commented Jun 15, 2018

Add np to sys.modules so that documentation can use `np.dtype` instead of `numpy.dtype` or `` np.dtype <numpy.dtype>

@mattip
Copy link
Member Author
mattip commented Jun 15, 2018

hmm, segfault when building the documentation.

@charris
Copy link
Member
charris commented Jun 16, 2018

Yeah, that is strange. Maybe a sphinx related library?

@mattip
Copy link
Member Author
mattip commented Jun 19, 2018

See PR #11377, there is a bug in calling PyInit_multiarray more than once on (at least) CPython3

@eric-wieser
Copy link
Member
eric-wieser commented Jun 19, 2018

Does the following work better:

aliases = {}
for name, module in sys.modules.items():
    parts = name.split('.', 1)
    if parts[0] == 'numpy':
        parts[0] = 'np'
        aliases[name] = module
sys.modules.update(aliases)

Uh oh!

There was an error while loading. Please reload this page.

@mattip mattip force-pushed the allow-np-domain branch from c44de8e to 259ac3f Compare June 19, 2018 23:05
@mattip
Copy link
Member Author
mattip commented Jun 19, 2018

It still may fail if new numpy c-extension imports are needed past this point, which should not be the case in documentation.

parts = name.split('.', 1)
if parts[0] == 'numpy':
parts[0] = 'np'
aliases[name] = module
Copy link
Member

Choose a reason for hiding this comment

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

I missed a line, sorry: name = '.'.join(parts)

@mattip
Copy link
Member Author
mattip commented Jun 20, 2018

Turns out that sys.modules is only part of the problem, we would also need to register all the numpy objects again as np objects. PythonDomain.findobj(...) searches a dictionary of registered objects, perhaps a more fruitful direction would be to tell findobj that np is an alias for numpy.

Closing this, it is the wrong approach.

@mattip mattip closed this Jun 20, 2018
@eric-wieser
Copy link
Member

I think this approach would work if you then also told sphinx to generate docs for things under np. instead of numpy - so pages like https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.dot.html would say np.dot at the top instead.

This might actually be a good idea from the perspective of matching source code, but worse from a search engine perspective.

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

Successfully merging this pull request may close these issues.

3 participants
0