Skip to content

Subclassed attributes are not serializable #10553

Closed
@kjordahl

Description

@kjordahl

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

No one assigned

    Labels

    BugCompatpandas objects compatability with Numpy or Python functionsSubclassingSubclassing pandas objects

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions