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

Cube units dropped after pickle #6378

Open
cpelley opened this issue Mar 24, 2025 · 0 comments
Open

Cube units dropped after pickle #6378

cpelley opened this issue Mar 24, 2025 · 0 comments
Assignees

Comments

@cpelley
Copy link

cpelley commented Mar 24, 2025

🐛 Bug Report

Could be a cf_units bug (I am as of yet unsure), but since my example uses iris cubes for now, I'll open here.
The issue is that, on pickling the cube, its units (cf_units) disappears.
This bug is exposed with use of multiprocessing, since that is reliant on pickling for serialisation.

How To Reproduce

Example where the units disappear after multiplying our cube by another with unit of 1:

>>> import pickle
>>> import iris.cube
>>> res = iris.cube.Cube(0, units='K') * iris.cube.Cube(0, units=1)
>>> res
<iris 'Cube' of unknown / (K) (scalar cube)>
>>> pickle.dump(res, open("/tmp/res.pkl", "wb")); pickle.load(open("/tmp/res.pkl", "rb"))
<iris 'Cube' of unknown / (unknown) (scalar cube)>

Where we don't multiply our cube by another with unit 1 (everything turns out OK):

>>> res = iris.cube.Cube(0, units='K')
>>> res
<iris 'Cube' of unknown / (K) (scalar cube)>
>>> pickle.dump(res, open("/tmp/res.pkl", "wb")); pickle.load(open("/tmp/res.pkl", "rb"))
<iris 'Cube' of unknown / (K) (scalar cube)>

Environment

as per sss/environments/default-2024_11_26:

Package/app version
cf_units 3.2.0
iris 3.11.0
Python 3.12.7

Workaround (of sorts)

cube.units = str(cube.units)
@cpelley cpelley changed the title Cube units lost after pickle Cube units dropped after pickle Mar 24, 2025
@cpelley cpelley self-assigned this Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

1 participant