Skip to content

Commit

Permalink
changed import style for pcodec
Browse files Browse the repository at this point in the history
  • Loading branch information
rabernat committed Feb 21, 2024
1 parent c9bfa6c commit f999831
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
5 changes: 2 additions & 3 deletions numcodecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,5 @@
from numcodecs.fletcher32 import Fletcher32
register_codec(Fletcher32)

with suppress(ImportError):
from numcodecs.pcodec import PCodec
register_codec(PCodec)
from numcodecs.pcodec import PCodec
register_codec(PCodec)
11 changes: 7 additions & 4 deletions numcodecs/pcodec.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Optional, Literal


import pcodec


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

try:
import pcodec
except ImportError:
pcodec = None

class PCodec(numcodecs.abc.Codec):
"""
Expand Down Expand Up @@ -50,6 +50,9 @@ def __init__(
float_mult_spec: Literal["enabled", "disabled"] = "enabled",
max_page_n: int = 262144,
):
if pcodec is None:
raise ImportError("pcodec is not available. Please install the pcodec package.")

# note that we use `level` instead of `compression_level` to
# match other codecs
self.level = level
Expand Down

0 comments on commit f999831

Please sign in to comment.