This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Pickling units
Type: behavior Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: abz64, r.david.murray
Priority: normal Keywords:

Created on 2016-11-30 20:25 by abz64, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg282099 - (view) Author: Adam (abz64) Date: 2016-11-30 20:25
See below code to show you can't round-trip units through pickle:

Python 3.5.1 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:49:46) [MSC v.1900 64 bit AMD64)]
import units
u = units.unit('myUnit')
x = u(3.0)
import pickle
f = open('C:/temp/what.pkl', 'wb')
pickle.dump(x, f)
f.close()
f = open('C:/temp/what.pkl', 'rb')
y = pickle.load(f)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-f17cfc395901> in <module>()
----> 1 y = pickle.load(f)

TypeError: __new__() missing 2 required positional arguments: 'num' and 'unit'
msg282100 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-11-30 20:28
unit is not part of the stdlib.  Please report this to whatever the upstream is for the package and/or to Anaconda.
msg282101 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2016-11-30 20:29
To clarify: it looks from your report like units hasn't implemented pickling support.  It isn't automatic for all classes.
History
Date User Action Args
2022-04-11 14:58:40adminsetgithub: 73030
2016-11-30 20:29:20r.david.murraysetmessages: + msg282101
2016-11-30 20:28:29r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg282100

resolution: third party
stage: resolved
2016-11-30 20:25:08abz64create