fleche-numpy 1.0.0__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.
- fleche_numpy-1.0.0/LICENSE +29 -0
- fleche_numpy-1.0.0/PKG-INFO +32 -0
- fleche_numpy-1.0.0/README.md +15 -0
- fleche_numpy-1.0.0/fleche_numpy/__init__.py +138 -0
- fleche_numpy-1.0.0/fleche_numpy.egg-info/PKG-INFO +32 -0
- fleche_numpy-1.0.0/fleche_numpy.egg-info/SOURCES.txt +10 -0
- fleche_numpy-1.0.0/fleche_numpy.egg-info/dependency_links.txt +1 -0
- fleche_numpy-1.0.0/fleche_numpy.egg-info/entry_points.txt +2 -0
- fleche_numpy-1.0.0/fleche_numpy.egg-info/requires.txt +2 -0
- fleche_numpy-1.0.0/fleche_numpy.egg-info/top_level.txt +1 -0
- fleche_numpy-1.0.0/pyproject.toml +33 -0
- fleche_numpy-1.0.0/setup.cfg +4 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Marvin Poul
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
* Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fleche-numpy
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: numpy digest hooks for fleche
|
|
5
|
+
Author-email: Marvin Poul <pmrv@posteo.de>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Project-URL: Homepage, https://github.com/pmrv/fleche
|
|
8
|
+
Project-URL: Documentation, https://fleche.readthedocs.io/
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: <3.15,>=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: fleche>=0.24.0.dev0
|
|
15
|
+
Requires-Dist: numpy>=1.26
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# fleche-numpy
|
|
19
|
+
|
|
20
|
+
[fleche](https://github.com/pmrv/fleche) digest hooks for numpy: arrays (`np.ndarray` and its subclasses), `np.bool_` and `np.timedelta64`.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install fleche-numpy
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Installing it is all it takes: fleche finds the hooks through its `fleche` entry point group.
|
|
27
|
+
Without it, fleche does not digest these values.
|
|
28
|
+
numpy number scalars (`np.float64`, `np.int32`, ...) need no hooks; fleche digests them itself.
|
|
29
|
+
|
|
30
|
+
How arrays are digested — dtype, shape and bytes, per field for structured dtypes, per element for object dtypes — is described in fleche's [numpy documentation](https://fleche.readthedocs.io/en/latest/digests/numpy.html).
|
|
31
|
+
|
|
32
|
+
This package lives in the fleche repository, under `src/fleche-numpy`, and is versioned and released independently of fleche itself.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# fleche-numpy
|
|
2
|
+
|
|
3
|
+
[fleche](https://github.com/pmrv/fleche) digest hooks for numpy: arrays (`np.ndarray` and its subclasses), `np.bool_` and `np.timedelta64`.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install fleche-numpy
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Installing it is all it takes: fleche finds the hooks through its `fleche` entry point group.
|
|
10
|
+
Without it, fleche does not digest these values.
|
|
11
|
+
numpy number scalars (`np.float64`, `np.int32`, ...) need no hooks; fleche digests them itself.
|
|
12
|
+
|
|
13
|
+
How arrays are digested — dtype, shape and bytes, per field for structured dtypes, per element for object dtypes — is described in fleche's [numpy documentation](https://fleche.readthedocs.io/en/latest/digests/numpy.html).
|
|
14
|
+
|
|
15
|
+
This package lives in the fleche repository, under `src/fleche-numpy`, and is versioned and released independently of fleche itself.
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""fleche digest hooks for numpy: arrays, ``np.bool_`` and ``np.timedelta64``.
|
|
2
|
+
|
|
3
|
+
Registered through the ``fleche`` entry point group (see :data:`digest_hooks`),
|
|
4
|
+
so installing this package is all it takes. Without it, fleche does not digest
|
|
5
|
+
these values.
|
|
6
|
+
|
|
7
|
+
numpy number scalars (``np.float64``, ``np.int32``, ...) are not handled here:
|
|
8
|
+
they are numbers, digested by fleche's own :mod:`fleche._numbers`.
|
|
9
|
+
|
|
10
|
+
The digest functions take the recursive digest as an argument, ``digest_bytes``,
|
|
11
|
+
returning the hex digest as bytes; the hooks pass :func:`fleche.digest.digest`.
|
|
12
|
+
:mod:`fleche_pandas` builds on :func:`timedelta64_length`.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from collections.abc import Callable
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
import numpy as np
|
|
19
|
+
|
|
20
|
+
from fleche.hashing import running_hash
|
|
21
|
+
from fleche.digest import Digest, Indigestible, digest
|
|
22
|
+
|
|
23
|
+
__all__ = [
|
|
24
|
+
"digest_hooks",
|
|
25
|
+
"digest_numpy",
|
|
26
|
+
"digest_timedelta64",
|
|
27
|
+
"timedelta64_length",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def digest_numpy(value, digest_bytes: Callable[[Any], bytes]) -> bytes:
|
|
32
|
+
"""Return the digest of the numpy *value*, in the format of *digest_bytes*."""
|
|
33
|
+
if isinstance(value, np.bool_):
|
|
34
|
+
# Not a numbers.Number since numpy 1.20; digests as the builtin bool.
|
|
35
|
+
return digest_bytes(bool(value))
|
|
36
|
+
with running_hash(type(value).__name__.encode()) as m:
|
|
37
|
+
m.update(digest_bytes(value.dtype.str))
|
|
38
|
+
m.update(digest_bytes(value.shape))
|
|
39
|
+
if value.dtype.names is not None:
|
|
40
|
+
for name in value.dtype.names:
|
|
41
|
+
m.update(digest_bytes(name))
|
|
42
|
+
m.update(digest_bytes(value[name])) # recurses into this arm
|
|
43
|
+
elif value.dtype.hasobject:
|
|
44
|
+
# tobytes() of an object array yields memory addresses, digest
|
|
45
|
+
# all elements by value instead
|
|
46
|
+
for element in value.ravel().tolist():
|
|
47
|
+
m.update(digest_bytes(element))
|
|
48
|
+
else:
|
|
49
|
+
m.update(value.tobytes())
|
|
50
|
+
return m.result
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Attoseconds in one of each fixed numpy timedelta unit; the attosecond is
|
|
54
|
+
# numpy's finest, so every fixed unit is a whole number of them.
|
|
55
|
+
_AS_PER_UNIT = {
|
|
56
|
+
"W": 7 * 24 * 3600 * 10**18,
|
|
57
|
+
"D": 24 * 3600 * 10**18,
|
|
58
|
+
"h": 3600 * 10**18,
|
|
59
|
+
"m": 60 * 10**18,
|
|
60
|
+
"s": 10**18,
|
|
61
|
+
"ms": 10**15,
|
|
62
|
+
"us": 10**12,
|
|
63
|
+
"ns": 10**9,
|
|
64
|
+
"ps": 10**6,
|
|
65
|
+
"fs": 10**3,
|
|
66
|
+
"as": 1,
|
|
67
|
+
}
|
|
68
|
+
# unit -> (salt, length of one unit). Y and M vary in length and numpy only
|
|
69
|
+
# compares them with each other, a year as twelve months, so they count months;
|
|
70
|
+
# the generic unit is a count still waiting for a unit, which numpy calls equal
|
|
71
|
+
# to that count of *every* unit, so it is digested as the bare count.
|
|
72
|
+
_TIMEDELTA64_SCALES = (
|
|
73
|
+
{unit: (b"timedelta64", n) for unit, n in _AS_PER_UNIT.items()}
|
|
74
|
+
| {"Y": (b"timedelta64[M]", 12), "M": (b"timedelta64[M]", 1)}
|
|
75
|
+
| {"generic": (b"timedelta64[generic]", 1)}
|
|
76
|
+
)
|
|
77
|
+
_NAT = np.iinfo(np.int64).min
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def digest_timedelta64(value, digest_bytes: Callable[[Any], bytes]) -> bytes | None:
|
|
81
|
+
"""Digest of the ``np.timedelta64`` *value* by its exact length, or None if
|
|
82
|
+
its unit is not known.
|
|
83
|
+
|
|
84
|
+
Equal lengths digest equal whatever the unit (``5 s``, ``5000 ms`` and
|
|
85
|
+
``500 * 10ms``); numpy's own ``==`` is not the reference, since it compares
|
|
86
|
+
two units in int64 after casting both to the finer one, which can wrap.
|
|
87
|
+
NaT, which equals nothing, is one digest in every unit.
|
|
88
|
+
"""
|
|
89
|
+
if int(value.view(np.int64)) == _NAT:
|
|
90
|
+
with running_hash(b"timedelta64[NaT]") as m:
|
|
91
|
+
pass
|
|
92
|
+
return m.result
|
|
93
|
+
try:
|
|
94
|
+
salt, n = timedelta64_length(value)
|
|
95
|
+
except KeyError:
|
|
96
|
+
return None
|
|
97
|
+
with running_hash(salt) as m:
|
|
98
|
+
m.update(digest_bytes(n))
|
|
99
|
+
return m.result
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def timedelta64_length(value) -> tuple[bytes, int]:
|
|
103
|
+
"""``(salt, length)`` of the non-NaT ``np.timedelta64`` *value*.
|
|
104
|
+
|
|
105
|
+
The length is in attoseconds for a fixed unit (salt ``timedelta64``), in
|
|
106
|
+
months for ``Y``/``M`` and the bare count for the generic unit. Raises
|
|
107
|
+
KeyError if the unit is not known.
|
|
108
|
+
"""
|
|
109
|
+
unit, multiple = np.datetime_data(value.dtype)
|
|
110
|
+
salt, per_unit = _TIMEDELTA64_SCALES[unit]
|
|
111
|
+
return salt, int(value.view(np.int64)) * multiple * per_unit
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def _digest_bytes(value: Any) -> bytes:
|
|
115
|
+
return digest(value).encode()
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _array_digest(value: np.ndarray) -> Digest:
|
|
119
|
+
return Digest(digest_numpy(value, _digest_bytes).decode())
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _bool_digest(value: np.bool_) -> Digest:
|
|
123
|
+
return Digest(digest_numpy(value, _digest_bytes).decode())
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _timedelta64_digest(value: np.timedelta64) -> Digest:
|
|
127
|
+
digested = digest_timedelta64(value, _digest_bytes)
|
|
128
|
+
if digested is None:
|
|
129
|
+
raise Indigestible(value)
|
|
130
|
+
return Digest(digested.decode())
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
#: The hooks fleche loads from this package's ``fleche``/``digest`` entry point.
|
|
134
|
+
digest_hooks = [
|
|
135
|
+
(np.ndarray, _array_digest),
|
|
136
|
+
(np.bool_, _bool_digest),
|
|
137
|
+
(np.timedelta64, _timedelta64_digest),
|
|
138
|
+
]
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fleche-numpy
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: numpy digest hooks for fleche
|
|
5
|
+
Author-email: Marvin Poul <pmrv@posteo.de>
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
Project-URL: Homepage, https://github.com/pmrv/fleche
|
|
8
|
+
Project-URL: Documentation, https://fleche.readthedocs.io/
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: <3.15,>=3.11
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: fleche>=0.24.0.dev0
|
|
15
|
+
Requires-Dist: numpy>=1.26
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# fleche-numpy
|
|
19
|
+
|
|
20
|
+
[fleche](https://github.com/pmrv/fleche) digest hooks for numpy: arrays (`np.ndarray` and its subclasses), `np.bool_` and `np.timedelta64`.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install fleche-numpy
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Installing it is all it takes: fleche finds the hooks through its `fleche` entry point group.
|
|
27
|
+
Without it, fleche does not digest these values.
|
|
28
|
+
numpy number scalars (`np.float64`, `np.int32`, ...) need no hooks; fleche digests them itself.
|
|
29
|
+
|
|
30
|
+
How arrays are digested — dtype, shape and bytes, per field for structured dtypes, per element for object dtypes — is described in fleche's [numpy documentation](https://fleche.readthedocs.io/en/latest/digests/numpy.html).
|
|
31
|
+
|
|
32
|
+
This package lives in the fleche repository, under `src/fleche-numpy`, and is versioned and released independently of fleche itself.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
fleche_numpy/__init__.py
|
|
5
|
+
fleche_numpy.egg-info/PKG-INFO
|
|
6
|
+
fleche_numpy.egg-info/SOURCES.txt
|
|
7
|
+
fleche_numpy.egg-info/dependency_links.txt
|
|
8
|
+
fleche_numpy.egg-info/entry_points.txt
|
|
9
|
+
fleche_numpy.egg-info/requires.txt
|
|
10
|
+
fleche_numpy.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fleche_numpy
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[tool.setuptools]
|
|
6
|
+
packages = ["fleche_numpy"]
|
|
7
|
+
|
|
8
|
+
[project]
|
|
9
|
+
name = "fleche-numpy"
|
|
10
|
+
# Bumped by release-please (release-type "python"); see release-please-config.json.
|
|
11
|
+
version = "1.0.0"
|
|
12
|
+
description = "numpy digest hooks for fleche"
|
|
13
|
+
authors = [
|
|
14
|
+
{ name="Marvin Poul", email="pmrv@posteo.de" },
|
|
15
|
+
]
|
|
16
|
+
readme = "README.md"
|
|
17
|
+
requires-python = ">=3.11,<3.15"
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
]
|
|
22
|
+
license = "BSD-3-Clause"
|
|
23
|
+
dependencies = [
|
|
24
|
+
'fleche >= 0.24.0.dev0',
|
|
25
|
+
'numpy >= 1.26',
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/pmrv/fleche"
|
|
30
|
+
Documentation = "https://fleche.readthedocs.io/"
|
|
31
|
+
|
|
32
|
+
[project.entry-points.'fleche']
|
|
33
|
+
digest = 'fleche_numpy:digest_hooks'
|