Skip to content

Commit

Permalink
Handle mypy for soft imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkinsspatial committed Nov 18, 2024
1 parent 44bce08 commit 5de9d2c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
15 changes: 11 additions & 4 deletions virtualizarr/readers/hdf/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dataclasses
from typing import List, Tuple, TypedDict, Union
from typing import TYPE_CHECKING, List, Tuple, TypedDict, Union

import numcodecs.registry as registry
import numpy as np
Expand All @@ -9,9 +9,16 @@

from virtualizarr.utils import soft_import

h5py = soft_import("h5py", "For reading hdf files")
hdf5plugin = soft_import("hdf5plugin", "For reading hdf files with filters")
imagecodecs = soft_import("imagecodecs", "For reading hdf files with filters")
if TYPE_CHECKING:
import h5py # type: ignore

h5py = soft_import("h5py", "For reading hdf files", strict=False)
hdf5plugin = soft_import(
"hdf5plugin", "For reading hdf files with filters", strict=False
)
imagecodecs = soft_import(
"imagecodecs", "For reading hdf files with filters", strict=False
)


_non_standard_filters = {
Expand Down
8 changes: 6 additions & 2 deletions virtualizarr/readers/hdf/hdf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from typing import Dict, Iterable, List, Mapping, Optional, Union
from typing import TYPE_CHECKING, Dict, Iterable, List, Mapping, Optional, Union

import numpy as np
from xarray import Dataset, Index, Variable
Expand All @@ -15,7 +15,11 @@
from virtualizarr.utils import _FsspecFSFromFilepath, check_for_collisions, soft_import
from virtualizarr.zarr import ZArray

h5py = soft_import("h5py", "For reading hdf files")
if TYPE_CHECKING:
import h5py # type: ignore


h5py = soft_import("h5py", "For reading hdf files", strict=False)


class HDFVirtualBackend(VirtualBackend):
Expand Down

0 comments on commit 5de9d2c

Please sign in to comment.