Skip to content

Commit

Permalink
Cleanup PCodec soft dependency (#647)
Browse files Browse the repository at this point in the history
* Disable `PCodec` if dependencies are unavailable

* Run `isort` on `pcodec` module

* Add release note

* Update release note

* style: pre-commit fixes

---------

Co-authored-by: David Stansby <dstansby@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
3 people authored Jan 17, 2025
1 parent d8d53bb commit 32545ec
Showing 3 changed files with 6 additions and 13 deletions.
4 changes: 4 additions & 0 deletions docs/release.rst
Original file line number Diff line number Diff line change
@@ -41,6 +41,10 @@ Fixes
~~~~~
* Fixes issue with ``Delta`` Zarr 3 codec not working with ``astype``.
By :user:`Norman Rzepka <normanrz>`, :issue:`664`
* Cleanup ``PCodec`` soft dependency.
Previously importing ``numcodecs.pcodec`` would work if ``pcodec`` is not installed,
but now it will fail to import. This mirrors the behaviour of other optional dependencies.
By :user:`John Kirkham <jakirkham>`, :issue:`647`
* Fixes issues with the upcoming ``zarr`` 3.0.0 release.
By :user:`Norman Rzepka <normanrz>`, :issue:`675`

10 changes: 1 addition & 9 deletions numcodecs/pcodec.py
Original file line number Diff line number Diff line change
@@ -2,12 +2,7 @@

from numcodecs.abc import Codec
from numcodecs.compat import ensure_contiguous_ndarray

try:
from pcodec import ChunkConfig, DeltaSpec, ModeSpec, PagingSpec, standalone
except ImportError: # pragma: no cover
standalone = None

from pcodec import ChunkConfig, DeltaSpec, ModeSpec, PagingSpec, standalone

DEFAULT_MAX_PAGE_N = 262144

@@ -58,9 +53,6 @@ def __init__(
delta_encoding_order: int | None = None,
equal_pages_up_to: int = DEFAULT_MAX_PAGE_N,
):
if standalone is None: # pragma: no cover
raise ImportError("pcodec must be installed to use the PCodec codec.")

# note that we use `level` instead of `compression_level` to
# match other codecs
self.level = level
5 changes: 1 addition & 4 deletions numcodecs/tests/test_pcodec.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import numpy as np
import pytest

from numcodecs.pcodec import PCodec

try:
# initializing codec triggers ImportError
PCodec()
from numcodecs.pcodec import PCodec
except ImportError: # pragma: no cover
pytest.skip("pcodec not available", allow_module_level=True)

0 comments on commit 32545ec

Please sign in to comment.