You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
partition objects cannot be passed through the pickle serialization library. Below are more details and a fix. If we want to implement it, I can make a PR in the near future. If not, someone who really wants to pickle their partitions can look at this for guidance.
I tried to pickle a partition object and was met with
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "home/gerrychain/partition/partition.py", line 115, in __getattr__
_k = self.__getitem__(key)
File "/home/gerrychain/gerrychain/partition/partition.py", line 109, in __getitem__
self._cache[key] = self.updaters[key](self)
KeyError: '__getstate__'
and while I don't understand the inner workings of the pickle library, I did manage to resolve the problem by redefining Partition.__getitem__ and Partition.__getattr__ to the following:
def __getitem__(self, key):
"""Allows accessing the values of updaters computed for this
Partition instance.
:param key: Property to access.
"""
try:
if key not in self._cache:
self._cache[key] = self.updaters[key](self)
return self._cache[key]
except:
return None
def __getattr__(self, key):
_k = self.__getitem__(key)
if _k == None:
raise AttributeError
return _k
The text was updated successfully, but these errors were encountered:
partition
objects cannot be passed through thepickle
serialization library. Below are more details and a fix. If we want to implement it, I can make a PR in the near future. If not, someone who really wants topickle
theirpartition
s can look at this for guidance.I tried to
pickle
apartition
object and was met withand while I don't understand the inner workings of the
pickle
library, I did manage to resolve the problem by redefiningPartition.__getitem__
andPartition.__getattr__
to the following:The text was updated successfully, but these errors were encountered: