Re: Idiomatic import for SciPy

Ralf Gommers <[email protected]> Fri, 26 May 2023 19:54:26 +0200
Newsgroups gmane.comp.python.scientific.devel
Message-ID <CABL7CQji95VQ9rc=Pe2_Dv=mjOBx3xoHn5uSjdvVa=CMB7DoGA@mail.gmail.com>
On Tue, May 23, 2023 at 7:40 PM Pamphile Roy <[email protected]> wrote:

> Hi everyone,
>
> Since SciPy 1.9, we now have a lazy import mechanism which allows us to do
> `import scipy` and then work on any submodules without waiting time due to
> the import itself.
>
> NumPy and Pandas, just to name these, have set a precedence for an
> idiomatic way of importing their library. This is arguably an advantage for
> introspection, debugging, teaching, consistency or even communication
> purposes. Hence, I would like to propose that we also adopt an idiomatic
> import style for SciPy.
>

We also have an idiomatic way, which is documented at
http://scipy.github.io/devdocs/reference/index.html#guidelines-for-importing-functions-from-scipy
and used throughout our docs and by users and downstream packages.

There's basically 3 ways of doing this, if we'd start from scratch:
1. import scipy.submodule  # use as scipy.submodule.func()
2. import scipy as sp  # use as sp.submodule.func()
3. from scipy import submodule  # use as submodule.func()

It's not clear which would be preferred if we'd have the luxury of starting
from scratch. Whole blog posts have been written about abbreviations like
`np` and `pd` being an anti-pattern for example, and the justification of
doing that in scipy is far weaker before our main namespace is essentially
empty, while for numpy you use it all the time so the 3 characters saved
matter a lot more.

Given the large amount of churn a change would cause and the quite limited
(if any) benefits here, I'd prefer to not change anything here.

Cheers,
Ralf


If we would want to move forward with that idea, I would propose to make a
> brainstorming session with interested people to discuss the topic. This
> could for instance be a topic for next week’s community call.
>
> Cheers,
> Pamphile
>
>
> _______________________________________________
> SciPy-Dev mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/scipy-dev.python.org/
> Member address: [email protected]
>

_______________________________________________
SciPy-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/scipy-dev.python.org/
Member address: [email protected]