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

Standard import hints #13696

Open
jarrodmillman opened this issue Jun 10, 2022 · 1 comment
Open

Standard import hints #13696

jarrodmillman opened this issue Jun 10, 2022 · 1 comment

Comments

@jarrodmillman
Copy link

@jarrodmillman jarrodmillman commented Jun 10, 2022

The following are standard import conventions for scientific Python packages:

import numpy as np
import scipy as sp
import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd
import networkx as nx

Recently in scipy/scipy#13049 the question arose whether to assume these import conventions in docstring examples made sense in a cut and paste scenario. Even if we make everything "self-contained" in the docstrings, it is still reasonable to think that there will be little code snippets online that will potentially assume these conventions.

Would it be reasonable to add a suggestion for these (and maybe a few others) so that you got a Hint: something like this:

(nx) [jarrod@x15 ~]$ ipython
Python 3.9.9 (main, Nov 19 2021, 00:00:00)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.4.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: sequence = nx.random_powerlaw_tree_sequence(100, tries=5000)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 sequence = nx.random_powerlaw_tree_sequence(100, tries=5000)

NameError: name 'nx' is not defined

Hint: If you are using NetworkX, try `import networkx as nx` first

In [2]:
@MrMino
Copy link
Member

@MrMino MrMino commented Jun 20, 2022

I think it's ok to do that as long as the necessary changes aren't invasive/complex/hacky. I myself don't have much interest in it, but I'd be happy to review a PR that adds this.

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

No branches or pull requests

2 participants