atlas-schema 0.2.1__tar.gz → 0.2.2__tar.gz

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,11 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atlas-schema
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Helper python package for ATLAS Common NTuple Analysis work.
5
5
  Project-URL: Homepage, https://github.com/scipp-atlas/atlas-schema
6
6
  Project-URL: Bug Tracker, https://github.com/scipp-atlas/atlas-schema/issues
7
7
  Project-URL: Discussions, https://github.com/scipp-atlas/atlas-schema/discussions
8
- Project-URL: Changelog, https://github.com/scipp-atlas/atlas-schema/releases
8
+ Project-URL: Documentation, https://atlas-schema.readthedocs.io/en/v0.2.2/
9
+ Project-URL: Releases, https://github.com/scipp-atlas/atlas-schema/releases
10
+ Project-URL: Release Notes, https://atlas-schema.readthedocs.io/en/latest/history.html
9
11
  Author-email: Giordon Stark <kratsg@gmail.com>
10
12
  License:
11
13
  Apache License
@@ -249,7 +251,7 @@ Requires-Dist: tbump>=6.7.0; extra == 'test'
249
251
  Requires-Dist: twine; extra == 'test'
250
252
  Description-Content-Type: text/markdown
251
253
 
252
- # atlas-schema v0.2.1
254
+ # atlas-schema v0.2.2
253
255
 
254
256
  [![Actions Status][actions-badge]][actions-link]
255
257
  [![Documentation Status][rtd-badge]][rtd-link]
@@ -1,4 +1,4 @@
1
- # atlas-schema v0.2.1
1
+ # atlas-schema v0.2.2
2
2
 
3
3
  [![Actions Status][actions-badge]][actions-link]
4
4
  [![Documentation Status][rtd-badge]][rtd-link]
@@ -60,7 +60,9 @@ docs = [
60
60
  Homepage = "https://github.com/scipp-atlas/atlas-schema"
61
61
  "Bug Tracker" = "https://github.com/scipp-atlas/atlas-schema/issues"
62
62
  Discussions = "https://github.com/scipp-atlas/atlas-schema/discussions"
63
- Changelog = "https://github.com/scipp-atlas/atlas-schema/releases"
63
+ Documentation = "https://atlas-schema.readthedocs.io/en/v0.2.2/"
64
+ Releases = "https://github.com/scipp-atlas/atlas-schema/releases"
65
+ "Release Notes" = "https://atlas-schema.readthedocs.io/en/latest/history.html"
64
66
 
65
67
 
66
68
  [tool.hatch]
@@ -94,7 +96,19 @@ packages = ["src/atlas_schema"]
94
96
 
95
97
  [tool.pytest.ini_options]
96
98
  minversion = "6.0"
97
- addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
99
+ addopts = [
100
+ "-ra",
101
+ "--showlocals",
102
+ "--strict-markers",
103
+ "--strict-config",
104
+ "--doctest-modules",
105
+ "--doctest-glob=*.rst",
106
+ "--cov",
107
+ "--cov-report=xml",
108
+ "--cov-report=term",
109
+ "--durations=20",
110
+ "--ignore=docs/conf.py",
111
+ ]
98
112
  xfail_strict = true
99
113
  filterwarnings = [
100
114
  "error",
@@ -102,9 +116,9 @@ filterwarnings = [
102
116
  log_cli_level = "INFO"
103
117
  testpaths = [
104
118
  "tests",
119
+ "docs",
105
120
  ]
106
121
 
107
-
108
122
  [tool.coverage]
109
123
  run.source = ["atlas_schema"]
110
124
  report.exclude_also = [
@@ -113,6 +127,7 @@ report.exclude_also = [
113
127
  ]
114
128
 
115
129
  [tool.mypy]
130
+ mypy_path = ["src"]
116
131
  files = ["src", "tests"]
117
132
  python_version = "3.9"
118
133
  warn_unused_configs = true
@@ -133,6 +148,7 @@ disallow_incomplete_defs = true
133
148
  module = [
134
149
  'awkward.*',
135
150
  'coffea.*',
151
+ 'dask_awkward.*',
136
152
  ]
137
153
  ignore_missing_imports = true
138
154
 
@@ -10,7 +10,8 @@ import warnings
10
10
 
11
11
  from atlas_schema._version import version as __version__
12
12
  from atlas_schema.enums import ParticleOrigin, PhotonID
13
+ from atlas_schema.utils import isin
13
14
 
14
15
  warnings.filterwarnings("ignore", module="coffea.*")
15
16
 
16
- __all__ = ["ParticleOrigin", "PhotonID", "__version__"]
17
+ __all__ = ["ParticleOrigin", "PhotonID", "__version__", "isin"]
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.2.1'
16
- __version_tuple__ = version_tuple = (0, 2, 1)
15
+ __version__ = version = '0.2.2'
16
+ __version_tuple__ = version_tuple = (0, 2, 2)
@@ -1,9 +1,31 @@
1
1
  from __future__ import annotations
2
2
 
3
- from enum import IntEnum
3
+ import sys
4
+ from enum import Enum, IntEnum
4
5
 
6
+ if sys.version_info >= (3, 11):
7
+ from enum import EnumType
8
+ else:
9
+ from enum import EnumMeta as EnumType
5
10
 
6
- class ParticleType(IntEnum):
11
+ from typing import Callable, TypeVar, cast
12
+
13
+ _E = TypeVar("_E", bound=Enum)
14
+
15
+
16
+ class MultipleEnumAccessMeta(EnumType):
17
+ """
18
+ Enum Metaclass to provide a way to access multiple values all at once.
19
+ """
20
+
21
+ def __getitem__(self: type[_E], key: str | tuple[str]) -> _E | list[_E]: # type:ignore[misc,override]
22
+ getitem = cast(Callable[[str], _E], super().__getitem__) # type:ignore[misc]
23
+ if isinstance(key, tuple):
24
+ return [getitem(name) for name in key]
25
+ return getitem(key)
26
+
27
+
28
+ class ParticleType(IntEnum, metaclass=MultipleEnumAccessMeta):
7
29
  """
8
30
  Taken from `ATLAS Truth Utilities for ParticleType <https://gitlab.cern.ch/atlas/athena/-/blob/74f43ff0910edb2a2bd3778880ccbdad648dc037/Generators/TruthUtils/TruthUtils/TruthClasses.h#L8-49>`_.
9
31
  """
@@ -50,7 +72,7 @@ class ParticleType(IntEnum):
50
72
  UnknownJet = 38
51
73
 
52
74
 
53
- class ParticleOrigin(IntEnum):
75
+ class ParticleOrigin(IntEnum, metaclass=MultipleEnumAccessMeta):
54
76
  """
55
77
  Taken from `ATLAS Truth Utilities for ParticleOrigin <https://gitlab.cern.ch/atlas/athena/-/blob/74f43ff0910edb2a2bd3778880ccbdad648dc037/Generators/TruthUtils/TruthUtils/TruthClasses.h#L51-103>`_.
56
78
  """
@@ -105,7 +127,7 @@ class ParticleOrigin(IntEnum):
105
127
  QCD = 45
106
128
 
107
129
 
108
- class PhotonID(IntEnum):
130
+ class PhotonID(IntEnum, metaclass=MultipleEnumAccessMeta):
109
131
  """
110
132
  Taken from the `EGamma Identification CP group's twiki <https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/EGammaIdentificationRun2#Photon_isEM_word>`_.
111
133
  """
@@ -0,0 +1,39 @@
1
+ from __future__ import annotations
2
+
3
+ from enum import Enum
4
+ from typing import TypeVar, Union, cast
5
+
6
+ import awkward as ak
7
+ import dask_awkward as dak
8
+
9
+ Array = TypeVar("Array", bound=Union[dak.Array, ak.Array])
10
+ _E = TypeVar("_E", bound=Enum)
11
+
12
+
13
+ def isin(haystack: Array, needles: dak.Array | ak.Array, axis: int = -1) -> Array:
14
+ """
15
+ Find needles in haystack.
16
+
17
+ This works by first transforming needles to an array with one more
18
+ dimension than the haystack, placing the needles at axis, and then doing a
19
+ comparison.
20
+
21
+ Args:
22
+ haystack (dak.Array or ak.Array): haystack of values.
23
+ needles (dak.Array or ak.Array): one-dimensional set of needles to find in haystack.
24
+ axis (int): the axis along which the comparison is performed
25
+
26
+ Returns:
27
+ dak.Array or ak.Array: result of comparison for needles in haystack
28
+ """
29
+ assert needles.ndim == 1, "Needles must be one-dimensional"
30
+ assert axis >= -1, "axis must be -1 or positive-valued"
31
+ assert axis < haystack.ndim + 1, "axis too large for the haystack"
32
+
33
+ # First, build up the transformation, with slice(None) indicating where to stick the needles
34
+ reshaper: list[None | slice] = [None] * haystack.ndim
35
+ axis = haystack.ndim if axis == -1 else axis
36
+ reshaper.insert(axis, slice(None))
37
+
38
+ # Note: reshaper needs to be a tuple for indexing purposes
39
+ return cast(Array, ak.any(haystack == needles[tuple(reshaper)], axis=-1))
File without changes
File without changes