-
-
Couldn't load subscription status.
- Fork 19.2k
Closed
Labels
BugCompatpandas objects compatability with Numpy or Python functionspandas objects compatability with Numpy or Python functionsSubclassingSubclassing pandas objectsSubclassing pandas objects
Milestone
Description
In a subclass of pandas objects, pickling an object doesn't serialize properties of an instance of that subclass, even if the attribute has been added to _metadata. It would be hard to override this behavior entirely in the subclass, because it will require updates to __getstate__ and __setstate__, and probably also an addition or subclass of BlockManager. It would be nice if the _metadata serialization was handled in the base pandas class.
Example:
class SubDataFrame(DataFrame):
_metadata = ['my_data']
@property
def _constructor(self):
return SubDataFrame
sdf = SubDataFrame()
sdf.my_data = 'foo'
sdf.to_pickle('tmp.pkl')
new_sdf = read_pickle('tmp.pkl')
new_sdf.my_data
raises AttributeError: 'SubDataFrame' object has no attribute 'my_data'
(edited original example for correctness)
Metadata
Metadata
Assignees
Labels
BugCompatpandas objects compatability with Numpy or Python functionspandas objects compatability with Numpy or Python functionsSubclassingSubclassing pandas objectsSubclassing pandas objects