[SciPy-User] problem with loading data from data_store

Ralf Gommers ralf.gommers@googlemail....
Sun Mar 25 15:55:22 CDT 2012


On Thu, Mar 22, 2012 at 10:33 PM, Ryan Krauss <ryanlists@gmail.com> wrote:

> I have some data sets stored using scipy.io.save_as_module.  I
> recently upgrade to 0.10 and I can no longer open this module.
> Further, I tried to reprocess my data and resave it and I am still
> getting the same error message.  Just a couple of lines are needed to
> recreate my problem:
>
> mydict = {'a':12.34}
> scipy.io.save_as_module('mymod',mydict)
> import mymod
>
> The response to the last command (import) is
>
> In [18]: import mymod
> ---------------------------------------------------------------------------
> AttributeError                            Traceback (most recent call last)
>
> /home/ryan/siue/Research/modeling/SFLR/system_ID/TMM/TMM_SFLR_model1.py
> in <module>()
> ----> 1
>      2
>      3
>      4
>      5
>
> /home/ryan/siue/Research/modeling/SFLR/system_ID/TMM/mymod.py in <module>()
>      1 import scipy.io.data_store as data_store
>      2 import mymod
> ----> 3 data_store._load(mymod)
>      4
>      5
>
> AttributeError: 'module' object has no attribute '_load'
>
>
> Can anyone help me with this?
>

You can add this in scipy/io/data_store.py:

def _load(module):
    """ Load data into module from a shelf with
        the same name as the module.
    """
    dir,filename = os.path.split(module.__file__)
    filebase = filename.split('.')[0]
    fn = os.path.join(dir, filebase)
    f = dumb_shelve.open(fn, "r")
    #exec( 'import ' + module.__name__)
    for i in f.keys():
        exec( 'import ' + module.__name__+ ';' +
              module.__name__+'.'+i + '=' + 'f["' + i + '"]')

This was caused by an incorrect removal of deprecated code in
https://github.com/scipy/scipy/commit/329a5e2713. So apparently
save_as_module() has been completely broken for 2 years without anyone
noticing.....

Proposal: fix save_as_module now so it can load data again, deprecate it
for 0.11 and remove it for 0.12.

Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120325/a69a6707/attachment.html 


More information about the SciPy-User mailing list