Skip to content

pickle and unpickle of sparse gives unusable object #32

@kretes

Description

@kretes

pickling and unpickling Sparse object gives an object that has some missing fields, and e.g. cannot be saved with Sparse.save.

Reproducible example:

sparse = Sparse(shape=(10,10,10))
sparse.set((1,1,1), np.array([[[20]]]))
sparse.save("/tmp/tmp.sparse")
with open("/tmp/tmp.sparse.pickle", "wb") as f:
    pickle.dump(sparse, f)
with open("/tmp/tmp.sparse.pickle", "rb") as f:
    sparse_loaded  =pickle.load(f)
    sparse_loaded.save("/tmp/tmp.sparse")

fails with:

 File "env1/lib/python3.10/site-packages/chunky3d/chunky.py", line 1277, in save
    "_grid": {k: v.to_dict() for k, v in self._grid.items()},
  File "env1/lib/python3.10/site-packages/chunky3d/chunky.py", line 1277, in <dictcomp>
    "_grid": {k: v.to_dict() for k, v in self._grid.items()},
  File "env1/lib/python3.10/site-packages/chunky3d/chunk.py", line 34, in to_dict
    return {b"origin": self.origin, b"spacing": self.spacing, b"ndarray": self}
  File "env1/lib/python3.10/site-packages/chunky3d/chunk.py", line 27, in origin
    return self._origin
AttributeError: 'Chunk' object has no attribute '_origin'. Did you mean: 'origin'?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions