numcodecs-combinators 0.2.0__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.
Files changed (18) hide show
  1. numcodecs_combinators-0.2.2/.python-version +1 -0
  2. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/.readthedocs.yaml +2 -0
  3. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/PKG-INFO +8 -4
  4. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/mkdocs.yml +2 -1
  5. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/pyproject.toml +8 -3
  6. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/src/numcodecs_combinators/stack.py +50 -3
  7. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/tests/test_stack.py +9 -0
  8. numcodecs_combinators-0.2.0/.python-version +0 -1
  9. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/.github/workflows/ci.yml +0 -0
  10. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/.github/workflows/publish.yml +0 -0
  11. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/.gitignore +0 -0
  12. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/LICENSE +0 -0
  13. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/README.md +0 -0
  14. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/docs/index.md +0 -0
  15. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/docs/requirements.txt +0 -0
  16. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/src/numcodecs_combinators/__init__.py +0 -0
  17. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/src/numcodecs_combinators/abc.py +0 -0
  18. {numcodecs_combinators-0.2.0 → numcodecs_combinators-0.2.2}/src/numcodecs_combinators/py.typed +0 -0
@@ -0,0 +1 @@
1
+ 3.10
@@ -12,4 +12,6 @@ python:
12
12
  install:
13
13
  - method: pip
14
14
  path: .
15
+ extra_requirements:
16
+ - xarray
15
17
  - requirements: docs/requirements.txt
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: numcodecs-combinators
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Combinator codecs for the `numcodecs` buffer compression API
5
5
  License: Copyright (c) 2024, Juniper Tyree
6
6
 
@@ -378,9 +378,13 @@ License: Copyright (c) 2024, Juniper Tyree
378
378
  This Source Code Form is "Incompatible With Secondary Licenses", as
379
379
  defined by the Mozilla Public License, v. 2.0.
380
380
  License-File: LICENSE
381
- Requires-Python: >=3.12
382
- Requires-Dist: numcodecs~=0.13
383
- Requires-Dist: numpy~=2.2
381
+ Requires-Python: >=3.10
382
+ Requires-Dist: numcodecs<0.15,>=0.13.0
383
+ Requires-Dist: numpy~=2.0
384
+ Requires-Dist: typing-extensions~=4.6
385
+ Provides-Extra: xarray
386
+ Requires-Dist: dask>=2024.6; extra == 'xarray'
387
+ Requires-Dist: xarray>=2024.06; extra == 'xarray'
384
388
  Description-Content-Type: text/markdown
385
389
 
386
390
  [![image](https://img.shields.io/github/actions/workflow/status/juntyr/numcodecs-combinators/ci.yml?branch=main)](https://github.com/juntyr/numcodecs-combinators/actions/workflows/ci.yml?query=branch%3Amain)
@@ -54,4 +54,5 @@ plugins:
54
54
  modules: true
55
55
  inventories:
56
56
  - https://docs.python.org/3.12/objects.inv
57
- - https://numcodecs.readthedocs.io/en/v0.13.0/objects.inv
57
+ - https://numcodecs.readthedocs.io/en/v0.15.0/objects.inv
58
+ - https://docs.xarray.dev/en/v2025.01.0/objects.inv
@@ -4,12 +4,17 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "numcodecs-combinators"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Combinator codecs for the `numcodecs` buffer compression API"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
11
- requires-python = ">=3.12"
12
- dependencies = ["numcodecs~=0.13", "numpy~=2.2"]
11
+ requires-python = ">=3.10"
12
+ dependencies = [
13
+ "numcodecs>=0.13.0,<0.15",
14
+ "numpy~=2.0",
15
+ "typing-extensions~=4.6",
16
+ ]
17
+ optional-dependencies.xarray = [ "xarray>=2024.06", "dask>=2024.6" ]
13
18
 
14
19
  [dependency-groups]
15
20
  dev = ["mypy~=1.14", "pytest~=8.3"]
@@ -4,14 +4,19 @@ This module defines the [`CodecStack`][numcodecs_combinators.stack.CodecStack] c
4
4
 
5
5
  __all__ = ["CodecStack"]
6
6
 
7
- from collections.abc import Buffer
8
- from typing import Optional, Self, Callable
7
+ from typing import Optional, Callable
8
+ from typing_extensions import Buffer, Self # MSPV 3.12
9
9
 
10
10
  import numcodecs
11
11
  import numcodecs.compat
12
12
  import numcodecs.registry
13
13
  import numpy as np
14
14
 
15
+ try:
16
+ import xarray as xr
17
+ except ImportError:
18
+ pass
19
+
15
20
  from numcodecs.abc import Codec
16
21
 
17
22
  from .abc import CodecCombinatorMixin
@@ -52,7 +57,7 @@ class CodecStack(Codec, CodecCombinatorMixin, tuple[Codec]):
52
57
 
53
58
  __slots__ = ()
54
59
 
55
- codec_id = "combinators.stack"
60
+ codec_id: str = "combinators.stack" # type: ignore
56
61
 
57
62
  def __init__(self, *args: tuple[(dict | Codec), ...]):
58
63
  pass
@@ -151,8 +156,50 @@ class CodecStack(Codec, CodecCombinatorMixin, tuple[Codec]):
151
156
  out = np.empty(shape=shape, dtype=dtype)
152
157
  decoded = codec.decode(decoded, out).reshape(shape)
153
158
 
159
+ if isinstance(decoded, type(buf)):
160
+ return decoded
161
+
154
162
  return type(buf)(decoded) # type: ignore
155
163
 
164
+ def encode_decode_data_array(self, da: "xr.DataArray") -> "xr.DataArray":
165
+ """
166
+ Encode, then decode the data array in `da`.
167
+
168
+ The encode-decode computation may be deferred until the
169
+ [`compute`][xarray.DataArray.compute] method is called on the result.
170
+
171
+ This method requires the optional [`xarray`][xarray] dependency to be
172
+ installed.
173
+
174
+ Parameters
175
+ ----------
176
+ da : xr.DataArray
177
+ Data to be encoded.
178
+
179
+ Returns
180
+ -------
181
+ dec : xr.DataArray
182
+ Decoded data.
183
+ """
184
+
185
+ import xarray as xr
186
+
187
+ def encode_decode_data_array_single_chunk(
188
+ da: xr.DataArray,
189
+ ) -> xr.DataArray:
190
+ single_chunk = {dim: -1 for dim in da.dims}
191
+
192
+ # return early for zero-sized arrays
193
+ if da.size == 0:
194
+ return da.copy(deep=False).chunk(single_chunk)
195
+
196
+ # eagerly compute the input chunk and encode and decode it
197
+ decoded = self.encode_decode(da.values) # type: ignore
198
+
199
+ return da.copy(deep=False, data=decoded).chunk(single_chunk)
200
+
201
+ return xr.map_blocks(encode_decode_data_array_single_chunk, da)
202
+
156
203
  def get_config(self) -> dict:
157
204
  """
158
205
  Returns the configuration of the codec stack.
@@ -1,5 +1,6 @@
1
1
  import numcodecs
2
2
  import numpy as np
3
+ import xarray as xr
3
4
 
4
5
  import numcodecs_combinators
5
6
  from numcodecs_combinators.stack import CodecStack
@@ -41,6 +42,14 @@ def test_encode_decode():
41
42
  encoded_decoded = stack.encode_decode(b"abc")
42
43
  assert encoded_decoded == b"abc"
43
44
 
45
+ encoded_decoded = stack.encode_decode_data_array(xr.DataArray([1.0, 2.0, 3.0]))
46
+ assert encoded_decoded.equals(xr.DataArray([1.0, 2.0, 3.0]))
47
+
48
+ encoded_decoded = stack.encode_decode_data_array(
49
+ xr.DataArray([1.0, 2.0, 3.0]).chunk(1)
50
+ )
51
+ assert encoded_decoded.equals(xr.DataArray([1.0, 2.0, 3.0]))
52
+
44
53
 
45
54
  def test_map():
46
55
  stack = CodecStack(numcodecs.Zlib(level=9), numcodecs.CRC32())
@@ -1 +0,0 @@
1
- 3.12