[SciPy-dev] Advice on numpy/scipy namespace issue (ipython etc.)
Pearu Peterson
pearu at scipy.org
Sun Jan 8 13:42:59 CST 2006
On Sun, 8 Jan 2006, Tom Loredo wrote:
> Okay, as one who complained about the lack of numpy top-level
> objects in scipy's top-level namespace, I'm pursuaded by Travis
> and Pearu that a separation should be seriously considered, and
> that now is the time. I'd like some advice about handling
> the namespace split properly.
>
> I know that "from ... import *" is bad behavior, but particularly
> for interactive use it's sometimes irresistable. If I do
>
> from numpy import *
> from scipy import *
>
> is there any namespace collision I should be aware of?
The above import statements are safe (at least in theory).
> Are there any scipy modules or top-level functions with the same name
> as numpy's (or vice versa)? Both packages have "fft" at the top level,
> for example.
>
> "ipython -p scipy" imports top-level scipy into its namespace, but not
> top-level numpy. This doesn't seem right to me---surely one will be
> using array and zeros more often than fftpack---but the "import *"
> issue has to be settled if we want "-p scipy" to have all the
> handy numpy stuff at its top level.
ipython profiles should be here updated for numpy-0.9/scipy-0.4.4.
> As a more specific example, what exactly is the difference
> between numpy.fft and scipy.fft?
>
> As a quick exploration of the issue, I ran this:
>
> import numpy, scipy
>
> nall = numpy.__all__
>
> for name in scipy.__all__:
> if name in nall: print name
>
> The result was only 3 names: lib, fft, ifft. lib in particular is
> quite different in scipy vs. numpy. If the common name is kept,
> perhaps some convention should be recommended for * use, as in ipython,
> so users can count on lib meaning the same thing at an interactive
> prompt. It would probably be better to rename one of the libs (e.g.,
> "mlib" for scipy's since it's a matrix library, vs. numpy's more
> general-purpose lib), but I suppose it's late for that. I don't know
> if the fft name collision is an issue.
You must be using older numpy/scipy, numpy.__all__ does not contain 'lib'
anymore. In addtion, numpy namespace (as defined by numpy.__all__)
*-imports numpy.core and numpy.lib names. So, one should not use
numpy.lib.<libobject> but numpy.<libobject> instead. So, the name `lib`
in numpy will not cause any problems.
numpy and scipy have the following public objects with the same name
(before Travis patch on importing numpy symbols to scipy name space):
fft, ifft, linalg.
I think numpy.linalg should be renamed, say, to numpy.corelinalg (need
better name here), similar as numpy.fftpack was renamed to numpy.dft.
It appears that with the Travis patch, scipy.fft is actually
numpy.dft.fft. This is a bug and has a easy fix (I am starting to think
that importing numpy to scipy namespace is still a bad idea). Othervise
fft, ifft should not cause any problems if both scipy and numpy define them.
Thanks,
Pearu
More information about the Scipy-dev
mailing list