allow revalidation of already-proxied arrays

This commit is contained in:
sneakers-the-rat 2024-09-03 12:58:05 -07:00
parent d595e87e10
commit 4152af1f91
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D
3 changed files with 13 additions and 7 deletions

View file

@ -194,10 +194,7 @@ class H5Interface(Interface):
passthrough numpy-like interface to the dataset.
"""
input_types = (
H5ArrayPath,
H5Arraylike,
)
input_types = (H5ArrayPath, H5Arraylike, H5Proxy)
return_type = H5Proxy
@classmethod
@ -211,7 +208,7 @@ class H5Interface(Interface):
Check that the given array is a :class:`.H5ArrayPath` or something that
resembles one.
"""
if isinstance(array, H5ArrayPath):
if isinstance(array, (H5ArrayPath, H5Proxy)):
return True
if isinstance(array, (tuple, list)) and len(array) in (2, 3):
@ -242,6 +239,9 @@ class H5Interface(Interface):
"""Create an :class:`.H5Proxy` to use throughout validation"""
if isinstance(array, H5ArrayPath):
array = H5Proxy.from_h5array(h5array=array)
elif isinstance(array, H5Proxy):
# nothing to do, already proxied
pass
elif isinstance(array, (tuple, list)) and len(array) == 2: # pragma: no cover
array = H5Proxy(file=array[0], path=array[1])
elif isinstance(array, (tuple, list)) and len(array) == 3:

View file

@ -190,7 +190,7 @@ class VideoInterface(Interface):
OpenCV interface to treat videos as arrays.
"""
input_types = (str, Path, VideoCapture)
input_types = (str, Path, VideoCapture, VideoProxy)
return_type = VideoProxy
@classmethod
@ -204,7 +204,9 @@ class VideoInterface(Interface):
Check if array is a string or Path with a supported video extension,
or an opened VideoCapture object
"""
if VideoCapture is not None and isinstance(array, VideoCapture):
if (VideoCapture is not None and isinstance(array, VideoCapture)) or isinstance(
array, VideoProxy
):
return True
if isinstance(array, str):
@ -220,6 +222,8 @@ class VideoInterface(Interface):
"""Get a :class:`.VideoProxy` object for this video"""
if isinstance(array, VideoCapture):
proxy = VideoProxy(video=array)
elif isinstance(array, VideoProxy):
proxy = array
else:
proxy = VideoProxy(path=array)
return proxy

View file

@ -156,5 +156,7 @@ def test_interface_recursive(interfaces):
def test_interface_revalidate(all_interfaces):
"""
An interface should revalidate with the output of its initial validation
See: https://github.com/p2p-ld/numpydantic/pull/14
"""
_ = type(all_interfaces)(array=all_interfaces.array)