Skip to content

Pickling type of dtype object fails on NumPy 1.20 #18325

@jakirkham

Description

@jakirkham

Reproducing code example:

On NumPy 1.19.5, the following is possible...

In [1]: import pickle
   ...: import numpy as np

In [2]: t = type(np.arange(10, dtype="int64").dtype)

In [3]: pickle.loads(pickle.dumps(t))
Out[3]: numpy.dtype

However on NumPy 1.20.0 we see the following error...

In [1]: import pickle
   ...: import numpy as np

In [2]: t = type(np.arange(10, dtype="int64").dtype)

In [3]: pickle.loads(pickle.dumps(t))
---------------------------------------------------------------------------
PicklingError                             Traceback (most recent call last)
<ipython-input-3-c105e6dd98fb> in <module>
----> 1 pickle.loads(pickle.dumps(t))

PicklingError: Can't pickle <class 'numpy.dtype[int64]'>: attribute lookup dtype[int64] on numpy failed

Not sure if this is expected to fail, but we encountered this in our test suite when upgrading to NumPy 1.20

Error message:

---------------------------------------------------------------------------
PicklingError                             Traceback (most recent call last)
<ipython-input-3-c105e6dd98fb> in <module>
----> 1 pickle.loads(pickle.dumps(t))

PicklingError: Can't pickle <class 'numpy.dtype[int64]'>: attribute lookup dtype[int64] on numpy failed

NumPy/Python version information:

1.20.0 3.9.1 | packaged by conda-forge | (default, Jan 26 2021, 01:32:59) 
[Clang 11.0.1 ]

cc @madsbk @pentschev @quasiben

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions