Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[python]: Fix datatype pickling #4621

Merged
merged 3 commits into from
Aug 30, 2022
Merged

Conversation

OneRaynyDay
Copy link
Contributor

During the __reduce__ phase of a parametric dtype like pl.Datatime("ns") pickling we get:

(<function copyreg._reconstructor(cls, base, state)>,
 (polars.datatypes.Datetime, object, None),
 {'tu': 'ns', 'tz': None})

,but copyreg's reconstructor calls __new__ which we changed to make sure we can support singleton type objects:

def _reconstructor(cls, base, state):
    if base is object:
        obj = object.__new__(cls)
    else:
        obj = base.__new__(cls, state)
        if base.__init__ != object.__init__:
            base.__init__(obj, state)
    return obj

here, object.__new__(cls) returns the cls itself not an instance. We need to have a custom reconstructor in order to get this to work.

@OneRaynyDay OneRaynyDay changed the title Fix datatype pickling fix[python]: Fix datatype pickling Aug 29, 2022
@github-actions github-actions bot added the python Related to Python Polars label Aug 29, 2022
@ritchie46
Copy link
Member

Thanks for the fix!

@ritchie46 ritchie46 merged commit 5a6b32f into pola-rs:master Aug 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants