legend-pydataobj 1.11.10__py3-none-any.whl → 1.11.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: legend_pydataobj
3
- Version: 1.11.10
3
+ Version: 1.11.12
4
4
  Summary: LEGEND Python Data Objects
5
5
  Author: The LEGEND Collaboration
6
6
  Maintainer: The LEGEND Collaboration
@@ -1,6 +1,6 @@
1
- legend_pydataobj-1.11.10.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
1
+ legend_pydataobj-1.11.12.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
2
2
  lgdo/__init__.py,sha256=QMYK9HhoMi0pbahPN8mPD18gyTxscFgo7QKfCxVhy-0,3196
3
- lgdo/_version.py,sha256=8C1gggsLVh7AtWQynH0LD96q9_ChbquuufT1aPfdUFU,515
3
+ lgdo/_version.py,sha256=hxlOhf24ZalCiOeNPQ1JrEkKFcqpC8KtaFBcmCfZxFU,515
4
4
  lgdo/cli.py,sha256=s_EWTBWW76l7zWb6gaTSTjiT-0RzzcYEmjeFEQCVxfk,4647
5
5
  lgdo/lgdo_utils.py,sha256=6a2YWEwpyEMXlAyTHZMO01aqxy6SxJzPZkGNWKNWuS0,2567
6
6
  lgdo/lh5_store.py,sha256=5BzbJA9sLcqjp8bJDc2olwOiw0VS6rmfg3cfh1kQkRY,8512
@@ -16,7 +16,7 @@ lgdo/compression/varlen.py,sha256=6ZZUItyoOfygDdE0DyoISeFZfqdbH6xl7T0eclfarzg,15
16
16
  lgdo/lh5/__init__.py,sha256=y1XE_mpFWwamrl7WVjAVSVB25X4PrEfdVXSneSQEmlQ,825
17
17
  lgdo/lh5/concat.py,sha256=5nO7dNSb0UEP9rZiWGTKH5Cfwsm5LSm3tBJM4Kd70u0,6336
18
18
  lgdo/lh5/core.py,sha256=HT50rolOtTijgaGFskRgzoRbC0w-kxrRS2v9O5Q9Ugo,14067
19
- lgdo/lh5/datatype.py,sha256=O_7BqOlX8PFMyG0ppkfUT5aps5HEqX0bpuKcJO3jhu0,1691
19
+ lgdo/lh5/datatype.py,sha256=ry3twFaosuBoskiTKqtBYRMk9PQAf403593xKaItfog,1827
20
20
  lgdo/lh5/exceptions.py,sha256=3kj8avXl4eBGvebl3LG12gJEmw91W0T8PYR0AfvUAyM,1211
21
21
  lgdo/lh5/iterator.py,sha256=ZaBBnmuNIjinwO0JUY55wLxX8Om9rVRRzXBC5uHmSKM,19772
22
22
  lgdo/lh5/store.py,sha256=3wAaQDd1Zmo0_bQ9DbB-FbKS4Uy_Tb642qKHXtZpSw4,10643
@@ -33,7 +33,7 @@ lgdo/lh5/_serializers/read/utils.py,sha256=YfSqPO-83A1XvhhuULxQ0Qz2A5ODa3sb7ApNx
33
33
  lgdo/lh5/_serializers/read/vector_of_vectors.py,sha256=765P8mElGArAaEPkHTAUXFQ47t1_3-3BQAete0LckBQ,7207
34
34
  lgdo/lh5/_serializers/write/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
35
  lgdo/lh5/_serializers/write/array.py,sha256=66DKnW2yqIBlUGNBPWcE-m4W0B2-nTKusDHGX9m6GY0,3223
36
- lgdo/lh5/_serializers/write/composite.py,sha256=eEfisBAxpF1Q8v4AbORbBQyxg0p5ugMo9cBjicOC5KI,9979
36
+ lgdo/lh5/_serializers/write/composite.py,sha256=qYJIqpQxc1a0hmazxYCPMv-ar9_TsyK-zWcBmPleMfM,10011
37
37
  lgdo/lh5/_serializers/write/scalar.py,sha256=JPt_fcdTKOSFp5hfJdcKIfK4hxhcD8vhOlvDF-7btQ8,763
38
38
  lgdo/lh5/_serializers/write/vector_of_vectors.py,sha256=puGQX9XF5P_5DVbm_Cc6TvPrsDywgBLSYtkqFNltbB4,3493
39
39
  lgdo/types/__init__.py,sha256=DNfOErPiAZg-7Gygkp6ZKAi20Yrm1mfderZHvKo1Y4s,821
@@ -44,13 +44,13 @@ lgdo/types/fixedsizearray.py,sha256=7RjUwTz1bW0pcrdy27JlfrXPAuOU89Kj7pOuSUCojK8,
44
44
  lgdo/types/histogram.py,sha256=y6j2VDuGYYnLy7WI4J90ApS0PAwic4kCpouZPX09Nus,19974
45
45
  lgdo/types/lgdo.py,sha256=RQ2P70N7IWMBDnLLuJI3sm6zQTIKyOMSsKZtBNzmE90,2928
46
46
  lgdo/types/scalar.py,sha256=c5Es2vyDqyWTPV6mujzfIzMpC1jNWkEIcvYyWQUxH3Q,1933
47
- lgdo/types/struct.py,sha256=Q0OWLVd4B0ciLb8t6VsxU3MPbmGLZ7WfQNno1lSQS0Q,4918
47
+ lgdo/types/struct.py,sha256=m3pYfGfKptV8ti3wb4n1nsPKMvhjdWCFoRdR5YooZBM,6353
48
48
  lgdo/types/table.py,sha256=VIHQOPXJHJgiCjMMb_p7EdbcCqLFSObHMdHSxC1Dm5Y,19212
49
49
  lgdo/types/vectorofvectors.py,sha256=K8w7CZou857I9YGkeOe2uYB20gbHl4OV9xhnnJPNOjc,24665
50
50
  lgdo/types/vovutils.py,sha256=7BWPP0BSj-92ifbCIUBcfqxG5-TS8uxujTyJJuDFI04,10302
51
51
  lgdo/types/waveformtable.py,sha256=f2tS4f1OEoYaTM5ldCX9zmw8iSISCT3t3wS1SrPdu_o,9901
52
- legend_pydataobj-1.11.10.dist-info/METADATA,sha256=oWYdBOz-guRsPbd6918FxEhKM2C_8sQrhSqpp4AlL30,44444
53
- legend_pydataobj-1.11.10.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
54
- legend_pydataobj-1.11.10.dist-info/entry_points.txt,sha256=0KWfnwbuwhNn0vPUqARukjp04Ca6lzfZBSirouRmk7I,76
55
- legend_pydataobj-1.11.10.dist-info/top_level.txt,sha256=KyR-EUloqiXcQ62IWnzBmtInDtvsHl4q2ZJAZgTcLXE,5
56
- legend_pydataobj-1.11.10.dist-info/RECORD,,
52
+ legend_pydataobj-1.11.12.dist-info/METADATA,sha256=SzKnU5fc-xu0hVxQ3n5Zzq8tV-ws4Aw3L4A7mt95_Ic,44444
53
+ legend_pydataobj-1.11.12.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
54
+ legend_pydataobj-1.11.12.dist-info/entry_points.txt,sha256=0KWfnwbuwhNn0vPUqARukjp04Ca6lzfZBSirouRmk7I,76
55
+ legend_pydataobj-1.11.12.dist-info/top_level.txt,sha256=KyR-EUloqiXcQ62IWnzBmtInDtvsHl4q2ZJAZgTcLXE,5
56
+ legend_pydataobj-1.11.12.dist-info/RECORD,,
lgdo/_version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '1.11.10'
21
- __version_tuple__ = version_tuple = (1, 11, 10)
20
+ __version__ = version = '1.11.12'
21
+ __version_tuple__ = version_tuple = (1, 11, 12)
@@ -239,7 +239,9 @@ def _h5_write_struct(
239
239
  fields.extend(list(obj.keys()))
240
240
  obj.attrs.pop("datatype")
241
241
 
242
- obj.attrs["datatype"] = obj.datatype_name() + "{" + ",".join(fields) + "}"
242
+ obj.attrs["datatype"] = (
243
+ obj.datatype_name() + "{" + ",".join(sorted(fields)) + "}"
244
+ )
243
245
 
244
246
  # propagating wo_mode="ac" to nested LGDOs does not make any sense
245
247
  wo_mode = "append"
lgdo/lh5/datatype.py CHANGED
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  import re
4
4
  from collections import OrderedDict
5
+ from itertools import permutations as perm
5
6
 
6
7
  from .. import types as lgdo
7
8
 
@@ -14,7 +15,10 @@ _lgdo_datatype_map: dict[str, lgdo.LGDO] = OrderedDict(
14
15
  lgdo.ArrayOfEncodedEqualSizedArrays,
15
16
  r"^array_of_encoded_equalsized_arrays<1,1>\{.+\}$",
16
17
  ),
17
- (lgdo.Histogram, r"^struct\{binning,weights,isdensity\}$"),
18
+ (
19
+ lgdo.Histogram,
20
+ rf"^struct\{{(?:{'|'.join([','.join(p) for p in perm(['binning', 'weights', 'isdensity'])])})\}}$",
21
+ ),
18
22
  (lgdo.Struct, r"^struct\{.*\}$"),
19
23
  (lgdo.Table, r"^table\{.*\}$"),
20
24
  (lgdo.FixedSizeArray, r"^fixedsize_array<\d+>\{.+\}$"),
lgdo/types/struct.py CHANGED
@@ -5,7 +5,9 @@ utilities.
5
5
 
6
6
  from __future__ import annotations
7
7
 
8
+ import copy
8
9
  import logging
10
+ import re
9
11
  from collections.abc import Mapping
10
12
  from typing import Any
11
13
 
@@ -56,7 +58,21 @@ class Struct(LGDO, dict):
56
58
  # assign
57
59
  super().update({k: v})
58
60
 
59
- # call LGDO constructor to setup attributes
61
+ # check the datatype attribute passed by the user and sort the fields
62
+ # to ensure consistent behavior
63
+ if attrs is not None and "datatype" in attrs:
64
+ _attrs = copy.copy(dict(attrs))
65
+
66
+ if not _is_struct_datatype(self.datatype_name(), _attrs["datatype"]):
67
+ msg = (
68
+ f"datatype attribute ({self.attrs['datatype']}) is not "
69
+ f"compatible with class datatype!"
70
+ )
71
+ raise ValueError(msg)
72
+
73
+ _attrs["datatype"] = _sort_datatype_fields(_attrs["datatype"])
74
+ attrs = _attrs
75
+
60
76
  super().__init__(attrs)
61
77
 
62
78
  def datatype_name(self) -> str:
@@ -64,7 +80,10 @@ class Struct(LGDO, dict):
64
80
 
65
81
  def form_datatype(self) -> str:
66
82
  return (
67
- self.datatype_name() + "{" + ",".join([str(k) for k in self.keys()]) + "}"
83
+ self.datatype_name()
84
+ + "{"
85
+ + ",".join(sorted([str(k) for k in self.keys()]))
86
+ + "}"
68
87
  )
69
88
 
70
89
  def update_datatype(self) -> None:
@@ -157,3 +176,34 @@ class Struct(LGDO, dict):
157
176
  "not possible. Call view_as() on the fields instead."
158
177
  )
159
178
  raise NotImplementedError(msg)
179
+
180
+
181
+ def _is_struct_datatype(dt_name, expr):
182
+ return re.search("^" + dt_name + r"\{(.*)\}$", expr) is not None
183
+
184
+
185
+ def _get_struct_fields(expr: str) -> list[str]:
186
+ assert _is_struct_datatype(".*", expr)
187
+
188
+ arr = re.search(r"\{(.*)\}$", expr).group(1).split(",")
189
+ if arr == [""]:
190
+ arr = []
191
+
192
+ return sorted(arr)
193
+
194
+
195
+ def _struct_datatype_equal(dt_name, dt1, dt2):
196
+ if any(not _is_struct_datatype(dt_name, dt) for dt in (dt1, dt2)):
197
+ return False
198
+
199
+ return _get_struct_fields(dt1) == _get_struct_fields(dt2)
200
+
201
+
202
+ def _sort_datatype_fields(expr):
203
+ assert _is_struct_datatype(".*", expr)
204
+
205
+ match = re.search(r"^(.*)\{.*\}$", expr)
206
+ struct_type = match.group(1)
207
+ fields = _get_struct_fields(expr)
208
+
209
+ return struct_type + "{" + ",".join(sorted([str(k) for k in fields])) + "}"