Skip to content

Commit 9d73ee8

Browse files
committed
Override dataclass __reduce__ to allow hashing by panel
1 parent ad6a05f commit 9d73ee8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/simdec/decomposition.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass
4+
from hashlib import blake2b
45
from typing import Literal
56

67
import numpy as np
@@ -46,6 +47,17 @@ class DecompositionResult:
4647
states: list[int]
4748
bin_edges: np.ndarray
4849

50+
def __reduce__(self):
51+
h = blake2b(key=b"result hashing", digest_size=20)
52+
53+
h.update(str(self.var_names).encode())
54+
h.update(str(self.statistic).encode())
55+
h.update(str(self.bins).encode())
56+
h.update(str(self.states).encode())
57+
h.update(str(self.bin_edges).encode())
58+
59+
return [h.hexdigest()]
60+
4961

5062
def decomposition(
5163
inputs: pd.DataFrame,

0 commit comments

Comments
 (0)