labelarray 0.1.0__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.
@@ -0,0 +1,187 @@
1
+ Metadata-Version: 2.4
2
+ Name: labelarray
3
+ Version: 0.1.0
4
+ Summary: Labelled N-D arrays in pure NumPy, with exact label semantics and reproducible reductions
5
+ Author: Rigoberto Leyva Salmeron
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/rleyvasal/labelarray
8
+ Keywords: numpy,arrays,labelled arrays,named axes,xarray,reproducibility
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Scientific/Engineering
13
+ Requires-Python: >=3.11
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: numpy>=2.0
17
+ Provides-Extra: xarray
18
+ Requires-Dist: xarray>=2024.6; extra == "xarray"
19
+ Requires-Dist: pandas>=2.2.2; extra == "xarray"
20
+ Provides-Extra: fast
21
+ Requires-Dist: numba>=0.60; extra == "fast"
22
+ Provides-Extra: dev
23
+ Requires-Dist: xarray>=2024.6; extra == "dev"
24
+ Requires-Dist: pandas>=2.2.2; extra == "dev"
25
+ Requires-Dist: numba>=0.60; extra == "dev"
26
+ Requires-Dist: pytest>=7.0; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # labelarray
30
+
31
+ Labelled N-D arrays in pure NumPy, with exact label semantics and
32
+ reproducible reductions. It needs NumPy only; xarray is used only to convert
33
+ to and from xarray objects. It is the array layer of
34
+ [tidy3a](https://github.com/rleyvasal/tidy3a), released on its own.
35
+
36
+ It is deliberately small. What it offers that other array libraries do not:
37
+
38
+ 1. **Exact labels.** Labels match only when they are the same kind
39
+ (booleans, numbers, times, durations, text, bytes) and exactly equal, in
40
+ lookups, alignment, and joins. The integer `2**53 + 1` never matches the
41
+ float `2**53`; pandas, and so xarray, pair labels through float64.
42
+ 2. **Reproducible reductions.** Float32 sums and means are correctly
43
+ rounded: the float32 nearest the exact result, the same in any memory
44
+ layout. Grouped reductions are bit-identical to reducing each group on
45
+ its own.
46
+ 3. **Collections.** Arrays sharing axes, with one label array per axis,
47
+ joined and aligned under those rules.
48
+
49
+ **Status:** version `0.1.0`, the first release on its own; the API may still
50
+ change before 1.0. What changed in each release is in
51
+ [CHANGELOG.md](CHANGELOG.md).
52
+
53
+ ## Installing
54
+
55
+ Requires Python 3.11 or newer.
56
+
57
+ ```bash
58
+ pip install labelarray # NumPy only
59
+ pip install "labelarray[xarray]" # with xarray: to_xarray() and from_xarray()
60
+ pip install "labelarray[fast]" # with Numba: compiled grouped float32 sums and means
61
+ ```
62
+
63
+ Results are the same with or without `fast`; it only makes large grouped
64
+ sums and means faster.
65
+
66
+ ## Arrays
67
+
68
+ An `Array` is a NumPy array with one name per axis, labels for any of its
69
+ axes, attributes, and a name:
70
+
71
+ ```python
72
+ import numpy as np
73
+ from labelarray import Array
74
+
75
+ air = Array(
76
+ np.array([[271.0, 272.0, 273.0], [281.0, 282.0, 283.0]], dtype="float32"),
77
+ dims=("lat", "time"),
78
+ coords={"lat": [10.0, 20.0], "time": np.arange("2026-01-01", "2026-01-04", dtype="datetime64[D]")},
79
+ attrs={"units": "K"},
80
+ name="air",
81
+ )
82
+ print(air.sel(lat=20.0).data) # [281. 282. 283.]
83
+ print(air.isel(time=[0, 2]).labels("time")) # ['2026-01-01' '2026-01-03']
84
+ print(air.reduce("mean", ["time"]).data) # [272. 282.]
85
+ ```
86
+
87
+ `isel` takes positions, slices, or masks; `sel` takes labels, looked up
88
+ exactly; one label or position removes the axis, a list keeps it.
89
+ `transpose`, `rename` (axes), `reduce` (sum, mean, min, max, median, std,
90
+ var, any, all, count, with `na_rm` and `min_count`), and `dot` (the sum of
91
+ products over named axes) complete the methods.
92
+
93
+ NumPy's ufuncs, `np.where`, and Python's operators broadcast by axis name.
94
+ Labels on a shared axis must match: the same labels in another order are
95
+ matched by label, and anything else is an `AlignError`. There is no outer
96
+ join by default; ask for one with `Collection.join`.
97
+
98
+ ```python
99
+ import numpy as np
100
+ from labelarray import Array
101
+
102
+ a = Array([1.0, 2.0, 3.0], ("x",), {"x": [1, 2, 3]})
103
+ b = Array([30.0, 10.0, 20.0], ("x",), {"x": [3, 1, 2]})
104
+ print((a + b).data) # [11. 22. 33.]
105
+ print(np.sqrt(a * 4).data) # [2. 2.82842712 3.46410162]
106
+ ```
107
+
108
+ Labels are copied once into a read-only array the library owns, and each
109
+ label array's index is built on first use and kept with it: a sorted index,
110
+ a sort-once index for unsorted labels, or a grid index for evenly spaced
111
+ numbers and times, which looks labels up arithmetically. `register_index`
112
+ adds index classes for other label types, under the same exactness
113
+ obligations.
114
+
115
+ ## Collections
116
+
117
+ A `Collection` holds variables with different axes, each axis with one size
118
+ and at most one label array:
119
+
120
+ ```python
121
+ from labelarray import Array, Collection
122
+
123
+ left = Collection({"a": Array([1.0, 2.0, 3.0], ("k",))}, {"k": [1, 3, 5]})
124
+ right = Collection({"b": Array([10.0, 20.0], ("k",))}, {"k": [5, 1]})
125
+ both = left.join(right, "inner")
126
+ print(both.coords["k"]) # [1 5]
127
+ print(both.array("b").data) # [20. 10.]
128
+ print(left.join(right, "left").array("b").data) # [20. nan 10.]
129
+ ```
130
+
131
+ `isel`, `sel`, `select` (variables), `assign`, `rename` (variables), `join`
132
+ (left, inner, or outer), `nearest` (each label matched to its nearest within
133
+ a tolerance), `to_dict`, `to_xarray`, and `from_xarray` are its methods.
134
+ Missing positions after a join promote integers and booleans as xarray
135
+ does, and attributes that conflict are dropped.
136
+
137
+ ## Grouping
138
+
139
+ A `Grouping` assigns each position a group code; `factorize` makes one from
140
+ key values, optionally after a key transform (`Bins`, `Duration`, `Round`,
141
+ `GridCells`), with every missing key (NaN, NaT) one group, dropped unless
142
+ asked for. `grouped.reduce` reduces every group at once:
143
+
144
+ ```python
145
+ import numpy as np
146
+ from labelarray import Array, Grouping, factorize, grouped
147
+
148
+ intensity = Array(np.array([10, 20, 30, 40, 50], dtype="float32"), ("point",))
149
+ codes, labels = factorize(np.array([0, 0, 1, 1, 2]))
150
+ rings = Grouping(codes, labels)
151
+ print(grouped.reduce(intensity, "mean", rings, "point", "ring").data) # [15. 35. 50.]
152
+ print(grouped.counts(rings, "ring").data) # [2 2 1]
153
+ ```
154
+
155
+ `grouped.broadcast` puts a result per group back on each position.
156
+
157
+ ## Errors
158
+
159
+ Every error is a `LabelArrayError` (a `ValueError`): `LabelError` for labels
160
+ that cannot be found, ordered, or compared; `AlignError` for axes that
161
+ cannot be paired; `GroupError` for keys that cannot be grouped; and
162
+ `ShapeError` for axis names, sizes, and ranks that do not fit.
163
+
164
+ ## Development
165
+
166
+ From a checkout, install the development dependencies and run the tests:
167
+
168
+ ```bash
169
+ python -m pip install -e ".[dev]"
170
+ python -m pytest -q
171
+ ```
172
+
173
+ xarray and pandas are test dependencies: the tests check the library against
174
+ xarray and its label lookups against pandas. Before pushing, run the CI
175
+ checks in fresh environments with only declared dependencies (requires
176
+ [uv](https://docs.astral.sh/uv/)):
177
+
178
+ ```bash
179
+ scripts/check.sh
180
+ ```
181
+
182
+ The [release procedure](docs/releasing.md) describes the GitHub Release
183
+ workflow.
184
+
185
+ ## License
186
+
187
+ MIT
@@ -0,0 +1,19 @@
1
+ labelarray/__init__.py,sha256=wzbqZlZjLGMrWrdmdceqHBGuEdYHUOd4iiod5ntuKFY,2311
2
+ labelarray/__version__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
3
+ labelarray/_compiled.py,sha256=6DFveFFYoihzAT8P7-aLyZtrx0HJikvsb7sYXf7Nzvk,4592
4
+ labelarray/align.py,sha256=EFgfCuGj5kpRXOhrhJjYB9b5Z93vSfkjAs6HDyA_cCE,1715
5
+ labelarray/array.py,sha256=HJr3aWEWbkIFQFt70G0WkHysdYrireuOtUj628PKDLo,22052
6
+ labelarray/collection.py,sha256=yc7fsT3UHJviq8sELzpAnxqv7_K7RCMfPT0tapkSPHM,13307
7
+ labelarray/contract.py,sha256=JKvVzXo_xrZdO3dnn_s1EoyxBUZB5SSz_7yOahPNbG4,2706
8
+ labelarray/errors.py,sha256=saQfw2361CttBnsi5xQXKPvri_m-8iXKJReyvaCOc-o,612
9
+ labelarray/grouped.py,sha256=IaWEtACEg8fXkZSY-zm2fkwzJKOS1OivkBJS0txIgGA,13089
10
+ labelarray/index.py,sha256=PZbICb7Sr8CJuiQh03-JeMpYSr0vi0Rr5mdvI6i1jkc,21902
11
+ labelarray/labels.py,sha256=MRUWlIMz2FcPvr8Y2Mmbd5bLKpU6t2frrcGLVGQF1pM,9810
12
+ labelarray/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ labelarray/sums.py,sha256=9I0hpGDFkBTLpkWHy4A3WsE2bor38GV_ZmmLAPBAtO0,16250
14
+ labelarray/transforms.py,sha256=AaE3cXoeNVg7oBfCpS1xRf6tkLnygAlbGYKRGkqS6zQ,28121
15
+ labelarray-0.1.0.dist-info/licenses/LICENSE,sha256=sjpfmtLhkcM74AL9VMpifL0CRdeiMoLyUO9OKZ_hg9I,1082
16
+ labelarray-0.1.0.dist-info/METADATA,sha256=sKG3e8GBCuiob_q-3ohd2P5VRUQB0F_CddmNNKrYa-A,6915
17
+ labelarray-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
18
+ labelarray-0.1.0.dist-info/top_level.txt,sha256=TUW9Diy4WR9SJn9-uvP4osLdZFrwXdYW3GB40EwdGL0,11
19
+ labelarray-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rigoberto Leyva Salmeron
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ labelarray