diff --git a/numcodecs/__init__.py b/numcodecs/__init__.py index 8b949d15..1d1f6d04 100644 --- a/numcodecs/__init__.py +++ b/numcodecs/__init__.py @@ -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) diff --git a/numcodecs/pcodec.py b/numcodecs/pcodec.py index ceb012f0..84597479 100644 --- a/numcodecs/pcodec.py +++ b/numcodecs/pcodec.py @@ -3,10 +3,7 @@ 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 +from pcodec import ChunkConfig, ModeSpec, PagingSpec, standalone DEFAULT_MAX_PAGE_N = 262144 @@ -49,9 +46,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 diff --git a/numcodecs/tests/test_pcodec.py b/numcodecs/tests/test_pcodec.py index c10549bd..4143cee6 100644 --- a/numcodecs/tests/test_pcodec.py +++ b/numcodecs/tests/test_pcodec.py @@ -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)