Skip to content

Commit

Permalink
Address incompatibility in syntax for data types
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaarrfk committed May 7, 2024
1 parent c85c3d2 commit 41e271e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion doc/tools/apigen.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _parse_module_with_import(self, uri):
continue

# figure out if obj is a function or class
if isinstance(obj, FunctionType | BuiltinFunctionType):
if isinstance(obj, (FunctionType, BuiltinFunctionType)):
functions.append(obj_str)
elif isinstance(obj, ModuleType) and 'skimage' in mod.__name__:
submodules.append(obj_str)
Expand Down
2 changes: 1 addition & 1 deletion skimage/feature/_fisher_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def learn_gmm(descriptors, *, n_modes=32, gm_args=None):
'order to use the Fisher vector functionality.'
)

if not isinstance(descriptors, list | np.ndarray):
if not isinstance(descriptors, (list, np.ndarray)):
raise DescriptorException(
'Please ensure descriptors are either a NumPY array, '
'or a list of NumPy arrays.'
Expand Down
2 changes: 1 addition & 1 deletion skimage/filters/thresholding.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def _validate_image_histogram(image, hist, nbins=None, normalize=False):
raise Exception("Either image or hist must be provided.")

if hist is not None:
if isinstance(hist, tuple | list):
if isinstance(hist, (tuple, list)):
counts, bin_centers = hist
else:
counts = hist
Expand Down
2 changes: 1 addition & 1 deletion skimage/io/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def __getitem__(self, n):
if hasattr(n, '__index__'):
n = n.__index__()

if not isinstance(n, int | slice):
if not isinstance(n, (int, slice)):
raise TypeError('slicing must be with an int or slice object')

if isinstance(n, int):
Expand Down
2 changes: 1 addition & 1 deletion skimage/measure/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ def ransac(
rng = np.random.default_rng(rng)

# in case data is not pair of input and output, male it like it
if not isinstance(data, tuple | list):
if not isinstance(data, (tuple, list)):
data = (data,)
num_samples = len(data[0])

Expand Down
2 changes: 1 addition & 1 deletion skimage/segmentation/_watershed.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _validate_inputs(image, markers, mask, connectivity):
markers_bool = local_minima(image, connectivity=connectivity) * mask
footprint = ndi.generate_binary_structure(markers_bool.ndim, connectivity)
markers = ndi.label(markers_bool, structure=footprint)[0]
elif not isinstance(markers, np.ndarray | list | tuple):
elif not isinstance(markers, (np.ndarray, list, tuple)):
# not array-like, assume int
# given int, assume that number of markers *within mask*.
markers = regular_seeds(image.shape, int(markers / (n_pixels / image.size)))
Expand Down
9 changes: 5 additions & 4 deletions skimage/transform/tests/test_geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,10 +747,11 @@ def test_inverse_all_transforms(tform):
assert_almost_equal(tform.inverse.inverse(SRC), tform(SRC))
# Test addition with inverse, not implemented for all
if not isinstance(
tform,
EssentialMatrixTransform
| FundamentalMatrixTransform
| PiecewiseAffineTransform,
tform, (
EssentialMatrixTransform,
FundamentalMatrixTransform,
PiecewiseAffineTransform,
)
):
assert_almost_equal((tform + tform.inverse)(SRC), SRC)
assert_almost_equal((tform.inverse + tform)(SRC), SRC)
Expand Down

0 comments on commit 41e271e

Please sign in to comment.