diegojromerolopez / gelidum

Freeze your objects in python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No numpy support?

volkerjaenisch opened this issue · comments

Dear @diegojromerolopez
I noticed that your code does not support numpy instances.

import numpy as np
data = np.empty(10)
frozen_data = freeze(data)

results in

Traceback (most recent call last):
  File "/home/volker/workspace/PROGRAMS/pycharm-2021.2.2/plugins/python/helpers/pydev/pydevd.py", line 1483, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/home/volker/workspace/PROGRAMS/pycharm-2021.2.2/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/home/volker/workspace/PYTHON4/ELDAmwl/src/ELDAmwl/sandbox/freezing.py", line 31, in <module>
    frozen_dummy1 = freeze(data)
  File "/home/volker/workspace/PYTHON4/gelidum/gelidum/freeze.py", line 41, in freeze
    return __freeze(obj=obj, on_update=on_update_func, on_freeze=on_freeze_func)
  File "/home/volker/workspace/PYTHON4/gelidum/gelidum/freeze.py", line 61, in __freeze
    return __freeze_object(obj, on_update=on_update, on_freeze=on_freeze)
  File "/home/volker/workspace/PYTHON4/gelidum/gelidum/freeze.py", line 113, in __freeze_object
    for attr, value in frozen_obj.__dict__.items():
AttributeError: 'numpy.ndarray' object has no attribute '__dict__'

I think that this feature is not hard to implement since with

array.flags.writeable=False

a readonly functionality is already available for numpy objects.

If you like I may come up with PR for that?

Probably some kind of plugin structure would be helpful to support the freezing of arbitrary data structures.

Cheers,
Volker

Hello @volkerjaenisch

Any help is appreciated, my experience with numpy is limited, so if you want to take start developing a PR I can work on it later also.

Best regards.

Dear @volkerjaenisch

I have started working in a prototype of numpy.ndarray freezing: #26

It is in an early stage and not ready for production, but any suggestion of what should have to be useful (I'm not a daily numpy user) is welcome.

Kind regards.

@diegojromerolopez
Thank you for still promoting this idea.
We learned that the data structures we liked to be frozen are to complex to freeze generically.
We have solved this problem on a higher level by enforcing that never inplace changes take place by design.
So please do not invest too much time in this numpy freezing if you do not like to use it.

If you like to have it tested anyway please come back to me.

Cheers,
Volker

Glad to know you could fix your issue. Thank you for your offer. As soon as I had some working prototype will notify you.

Kind regards!

This PR #26 has include numpy ndarray freeze support. Closing this issue until there are more specific user requests with respect to numpy.