p2p-ld / numpydantic

Type annotations for specifying, validating, and serializing arrays with arbitrary backends in Pydantic (and beyond)
https://numpydantic.readthedocs.io/
MIT License
57 stars 0 forks source link

import error exposure #29

Open RaymondWJang opened 4 days ago

RaymondWJang commented 4 days ago

Hello,

love the library so far. just one thing - would it be possible to expose the error trace for opencv import error? took me a bit longer than it should've to figure out that i need to separately add opencv-python to the env, as the only error shown when i ran

video = VideoProxy(path=video_path)
return video.shape

was Nonetype is not callable. (because VideoCapture gets automatically initialized as None when there's a cv2 import error.)

sneakers-the-rat commented 3 days ago

We talked a bit about this in person, jotting down TODOs:

The problem here is that we want to be minimal dependency as possible while allowing for third part expansion/declaration of interfaces that aren't in numpydantic package proper. To do that, each interface has an enabled property that is True when its dependencies are met and it can be used. The Interface.match method finds an interface that signals that it can be used for a given input via its check method (see Interfaces), but sometimes those package dependencies are required for that check method to run. Currently if no other interface matches, we fall back to the numpy interface (see Matching, NumpyInterface.priority), but that spuriously matches the input from most other interfaces so it passes validation silently. (eg. np.array('video.mp4') satisfies NDArray[Any, Any])

What we want here is an error message for "this looks like something that could be used with {x} interface, but you don't have the dependencies for it."

To make that happen we would need to