Opened 10 years ago

Closed 8 years ago

Last modified 8 years ago

#6494 closed defect (invalid)

sage should *never* ever import numpy by default on startup. Yet again it does!

Reported by: was Owned by: mabshoff
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: packages: standard Keywords:
Cc: was, jason, robertwb Merged in:
Authors: Reviewers: Mike Hansen
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by jdemeyer)

$ ./sage -startuptime |grep numpy
         decorators_numpy: 0.000 (IPython.testing)
                 numpy: 0.056 (complex_plot)
                  numpy.__config__: 0.000 (numpy)
                  version: 0.000 (numpy)
                  _import_tools: 0.000 (numpy)
                  add_newdocs: 0.035 (numpy)
                   numpy.lib: 0.026 (add_newdocs)
                    info: 0.000 (numpy.lib)
                    numpy.version: 0.000 (numpy.lib)
                    type_check: 0.016 (numpy.lib)
                     numpy.core.numeric: 0.015 (type_check)
                      multiarray: 0.001 (numpy.core.numeric)
                      umath: 0.001 (numpy.core.numeric)
                       numpy.core.multiarray: 0.000 (umath)
                      _internal: 0.002 (numpy.core.numeric)
                       numpy.compat: 0.000 (_internal)
                        _inspect: 0.000 (numpy.compat)
                        py3k: 0.000 (numpy.compat)
                      numerictypes: 0.001 (numpy.core.numeric)
                      _sort: 0.000 (numpy.core.numeric)
                      numeric: 0.002 (numpy.core.numeric)
                      defchararray: 0.001 (numpy.core.numeric)
                      records: 0.000 (numpy.core.numeric)
                      memmap: 0.000 (numpy.core.numeric)
                      scalarmath: 0.000 (numpy.core.numeric)
                       numpy.core.umath: 0.000 (scalarmath)
                      function_base: 0.000 (numpy.core.numeric)
                      machar: 0.000 (numpy.core.numeric)
                       numpy.core.fromnumeric: 0.000 (machar)
                      getlimits: 0.000 (numpy.core.numeric)
                      shape_base: 0.000 (numpy.core.numeric)
                      numpy.testing: 0.005 (numpy.core.numeric)
                       numpy.testing.utils: 0.004 (numpy.testing)
                        nosetester: 0.003 (numpy.testing.utils)
                       utils: 0.000 (numpy.testing)
                       numpytest: 0.000 (numpy.testing)
                    index_tricks: 0.004 (numpy.lib)
                     numpy.core.numerictypes: 0.000 (index_tricks)
                     numpy.core: 0.000 (index_tricks)
                     numpy.lib.twodim_base: 0.000 (index_tricks)
                      numpy.lib.utils: 0.001 (arraysetops)
                     numpy.matrixlib: 0.001 (index_tricks)
                      defmatrix: 0.001 (numpy.matrixlib)
                    stride_tricks: 0.000 (numpy.lib)
                    twodim_base: 0.000 (numpy.lib)
                    scimath: 0.000 (numpy.lib)
                     numpy.lib.type_check: 0.000 (scimath)
                    numpy.lib.function_base: 0.000 (numpy.lib)
                    numpy.linalg: 0.003 (numpy.lib)
                     linalg: 0.003 (numpy.linalg)
                      numpy.matrixlib.defmatrix: 0.000 (linalg)
                    npyio: 0.002 (numpy.lib)
                    financial: 0.000 (numpy.lib)
                    arrayterator: 0.000 (numpy.lib)
                   numpy.lib._compiled_base: 0.000 (add_newdocs)
                   numpy.lib.index_tricks: 0.000 (add_newdocs)
                  testing: 0.000 (numpy)
                  core: 0.000 (numpy)
                  compat: 0.000 (numpy)
                  lib: 0.000 (numpy)
                  fft: 0.001 (numpy)
                  polyutils: 0.000 (numpy)
                  polytemplate: 0.000 (numpy)
                  chebyshev: 0.005 (numpy)
                  mtrand: 0.002 (numpy)
                  ctypeslib: 0.001 (numpy)
                   numpy.core._internal: 0.000 (ctypeslib)
                  ma: 0.005 (numpy)
                  matrixlib: 0.000 (numpy)
0.056 numpy (complex_plot)
0.035 add_newdocs (numpy)

I think this is because of the new complex_plot module, which I think I positively reviewed, so this is my fault. To resolve this ticket, make that import sufficiently lazy. Also, make a doctest that verifies that numpy is not imported when Sage starts up.

Attachments (1)

trac_6494.patch (5.9 KB) - added by mhansen 9 years ago.

Download all attachments as: .zip

Change History (7)

Changed 9 years ago by mhansen

comment:1 Changed 9 years ago by mhansen

  • Authors set to Mike Hansen
  • Cc was added
  • Report Upstream set to N/A
  • Status changed from new to needs_review

I don't think you can cimport numpy without causing an import in the module. Thus, a number of things have to be lazily imported. This will cause a problem if people do

sage: from sage.finance.all import TimeSeries
sage: isinstance(foo, TimeSeries)

since TimeSeries? will be a LazyImport? object rather than a class. I'm not sure the best thing to do, but I've posted a patch anyway.

comment:2 Changed 9 years ago by jason

  • Cc jason added

numpy recently has made great improvements in its import speed, so maybe this isn't quite the issue it used to be?

comment:3 Changed 9 years ago by robertwb

  • Cc robertwb added

comment:4 Changed 8 years ago by jdemeyer

  • Description modified (diff)
  • Status changed from needs_review to needs_work

I'm not going to judge whether numpy imports are still an issue or not, but in any case the patch needs to be rebased:

patching file sage/calculus/all.py
Hunk #2 succeeded at 16 (offset 1 line).
patching file sage/finance/all.py
patching file sage/interfaces/gnuplot.py
patching file sage/plot/all.py
Hunk #2 FAILED at 21.
1 out of 2 hunks FAILED -- saving rejects to file sage/plot/all.py.rej
patching file sage/plot/plot3d/implicit_plot3d.py
Hunk #2 succeeded at 255 (offset 10 lines).
patching file sage/stats/all.py
patching file sage/stats/hmm/all.py

comment:5 Changed 8 years ago by mhansen

  • Milestone changed from sage-5.0 to sage-duplicate/invalid/wontfix
  • Resolution set to invalid
  • Status changed from needs_work to closed

This ticket is invalid now as all of the changes appearing in it are already in the Sage library.

comment:6 Changed 8 years ago by jdemeyer

  • Authors Mike Hansen deleted
  • Reviewers set to Mike Hansen

You shouldn't just close tickets, leave that to the release manager.

Note: See TracTickets for help on using tickets.