hist icon indicating copy to clipboard operation
hist copied to clipboard

[BUG] Unserializatable histogram generated with an empty hist.dask.Hist

Open yimuchen opened this issue 1 year ago • 0 comments

Describe the bug

hist.dask.Hist generates an unpickleable object if computed with no fill call

Steps to reproduce

import pickle

import dask
import dask_awkward
import hist.dask
import numpy

import awkward

h = hist.dask.Hist(hist.axis.Regular(10, 0, 1))
# h.fill(
#     dask_awkward.from_awkward(
#         awkward.from_numpy(numpy.random.random(size=20)), npartitions=1
#     )
# )
o = dask.compute(h)
print(o, type(o))
pickle.dump(o, open("hist_dask_test.pkl", "wb"))

Without the fill call, the the output still appears valid at the print statement, but the pickle statement will fail with the message:

Traceback (most recent call last):
  File "hist_dask_nofill.py", line 18, in <module>
    pickle.dump(o, open("hist_dask_test.pkl", "wb"))
AttributeError: Can't pickle local object 'Histogram.__init__.<locals>.<lambda>'

This is seen in the latest version hist==2.8.0

yimuchen avatar Sep 10 '24 17:09 yimuchen