Skip to content
5 changes: 3 additions & 2 deletions numcodecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@

register_codec(Fletcher32)

from numcodecs.pcodec import PCodec
with suppress(ImportError):
from numcodecs.pcodec import PCodec

register_codec(PCodec)
register_codec(PCodec)

Check warning on line 150 in numcodecs/__init__.py

View check run for this annotation

Codecov / codecov/patch

numcodecs/__init__.py#L150

Added line #L150 was not covered by tests
11 changes: 2 additions & 9 deletions numcodecs/pcodec.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
from typing import Literal, Optional

from pcodec import ChunkConfig, ModeSpec, PagingSpec, standalone

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

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


DEFAULT_MAX_PAGE_N = 262144


Expand Down Expand Up @@ -49,9 +45,6 @@ def __init__(
# TODO one day, add support for the Try* mode specs
mode_spec: Literal['auto', 'classic'] = 'auto',
):
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
Expand Down
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)

Expand Down
Loading