Skip to content

Commit 51f163b

Browse files
committed
xarray 2023 compatibility
1 parent 820e3c2 commit 51f163b

File tree

10 files changed

+22
-14
lines changed

10 files changed

+22
-14
lines changed

Diff for: bioimageio/core/_resource_tests.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def enable_determinism(
133133
try:
134134
os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
135135
try:
136-
import tensorflow as tf
136+
import tensorflow as tf # pyright: ignore[reportMissingTypeStubs]
137137
except ImportError:
138138
pass
139139
else:
@@ -147,7 +147,7 @@ def enable_determinism(
147147
if weight_formats is None or "keras_hdf5" in weight_formats:
148148
try:
149149
try:
150-
import keras
150+
import keras # pyright: ignore[reportMissingTypeStubs]
151151
except ImportError:
152152
pass
153153
else:

Diff for: bioimageio/core/backends/keras_backend.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
# by default, we use the keras integrated with tensorflow
1919
# TODO: check if we should prefer keras
2020
try:
21-
import tensorflow as tf
22-
from tensorflow import (
21+
import tensorflow as tf # pyright: ignore[reportMissingTypeStubs]
22+
from tensorflow import ( # pyright: ignore[reportMissingTypeStubs]
2323
keras, # pyright: ignore[reportUnknownVariableType,reportAttributeAccessIssue]
2424
)
2525

2626
tf_version = Version(tf.__version__)
2727
except Exception:
28-
import keras
28+
import keras # pyright: ignore[reportMissingTypeStubs]
2929

3030
tf_version = None
3131

Diff for: bioimageio/core/backends/onnx_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import warnings
33
from typing import Any, List, Optional, Sequence, Union
44

5-
import onnxruntime as rt
5+
import onnxruntime as rt # pyright: ignore[reportMissingTypeStubs]
66
from numpy.typing import NDArray
77

88
from bioimageio.spec._internal.type_guards import is_list, is_tuple

Diff for: bioimageio/core/backends/tensorflow_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Optional, Sequence, Union
33

44
import numpy as np
5-
import tensorflow as tf
5+
import tensorflow as tf # pyright: ignore[reportMissingTypeStubs]
66
from loguru import logger
77
from numpy.typing import NDArray
88

Diff for: bioimageio/core/io.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
Union,
1515
)
1616

17-
import h5py
17+
import h5py # pyright: ignore[reportMissingTypeStubs]
1818
import numpy as np
1919
from imageio.v3 import imread, imwrite # type: ignore
2020
from loguru import logger

Diff for: bioimageio/core/stat_calculators.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,15 @@ def compute(
139139
else:
140140
n = int(np.prod([tensor.sizes[d] for d in self._axes]))
141141

142-
var = xr.dot(c, c, dim=self._axes) / n
142+
if xr.__version__.startswith("2023"):
143+
var = ( # pyright: ignore[reportUnknownVariableType]
144+
xr.dot(c, c, dims=self._axes) / n
145+
)
146+
else:
147+
var = ( # pyright: ignore[reportUnknownVariableType]
148+
xr.dot(c, c, dim=self._axes) / n
149+
)
150+
143151
assert isinstance(var, xr.DataArray)
144152
std = np.sqrt(var)
145153
assert isinstance(std, xr.DataArray)

Diff for: bioimageio/core/weight_converters/keras_to_tensorflow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Union, no_type_check
55
from zipfile import ZipFile
66

7-
import tensorflow
7+
import tensorflow # pyright: ignore[reportMissingTypeStubs]
88

99
from bioimageio.spec._internal.io import download
1010
from bioimageio.spec._internal.version_type import Version
@@ -24,7 +24,7 @@
2424
from tensorflow import keras # type: ignore
2525
except Exception:
2626
# if the above fails try to export with the standalone keras
27-
import keras
27+
import keras # pyright: ignore[reportMissingTypeStubs]
2828

2929

3030
def convert(

Diff for: dev/env-py38.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ dependencies:
3939
- torchvision
4040
- tqdm
4141
- typing-extensions
42-
- xarray>=2024.01,<2025.3.0
42+
- xarray>=2023.01,<2025.3.0
4343
- pip:
4444
- -e ..

Diff for: scripts/show_diff.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from tempfile import TemporaryDirectory
44

5-
import pooch
5+
import pooch # pyright: ignore[reportMissingTypeStubs]
66

77
from bioimageio.core import load_description, save_bioimageio_yaml_only
88

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"ruyaml",
4343
"tqdm",
4444
"typing-extensions",
45-
"xarray>=2024.01,<2025.3.0",
45+
"xarray>=2023.01,<2025.3.0",
4646
],
4747
include_package_data=True,
4848
extras_require={

0 commit comments

Comments
 (0)