Skip to content

Commit

Permalink
Merge pull request #78 from lgray/fix_hist_meta_assignment
Browse files Browse the repository at this point in the history
fix: axes name assignments should persist through .copy() and .compute()
  • Loading branch information
martindurant authored Apr 26, 2023
2 parents b92a7be + bf10050 commit ee74738
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/dask_histogram/boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,13 @@ def __init__(
self._staged: AggHistogram | None = None
self._dask_name: str | None = None
self._dask: HighLevelGraph | None = None
self._histref = (
axes if isinstance(axes, tuple) else (axes,),
storage,
metadata,

@property
def _histref(self):
return (
tuple(self.axes),
self.storage_type(),
self.metadata,
)

def __iadd__(self, other):
Expand Down
38 changes: 38 additions & 0 deletions tests/test_boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,41 @@ def test_add(use_weights):
if use_weights:
assert np.allclose(h3.variances(), c3.variances())
assert np.allclose(h4.variances(), c3.variances())


def test_name_assignment():
import dask.array as da

hist = pytest.importorskip("hist")
import hist.dask

x = da.random.normal(size=100)
h1 = hist.dask.Hist(hist.axis.Regular(10, -2, 2, name="ax1"))
h2 = h1.copy()
h1.fill(x)
h2.axes.name = ("ax2",)
h2.fill(x)

assert h1.axes.name == ("ax1",)
assert h2.axes.name == ("ax2",)

h1c = h1.compute()
h2c = h2.compute()

assert h1c.axes.name == ("ax1",)
assert h2c.axes.name == ("ax2",)


def test_histref_pickle():
import pickle

import dask.array as da

hist = pytest.importorskip("hist")
import hist.dask

x = da.random.normal(size=100)
h1 = hist.dask.Hist(hist.axis.Regular(10, -2, 2, name="ax1"))
h1.fill(x) # forces the internal state histref update

pickle.dumps(h1._histref)

0 comments on commit ee74738

Please sign in to comment.