use np.array rather than ndarray to coerce lists

This commit is contained in:
sneakers-the-rat 2024-05-17 17:43:37 -07:00
parent 5e90c1bee1
commit 9c41705883
Signed by untrusted user who does not match committer: jonny
GPG key ID: 6DCB96EF1E4D232D

View file

@ -8,12 +8,14 @@ from numpydantic.interface.interface import Interface
try: try:
from numpy import ndarray from numpy import ndarray
import numpy as np
ENABLED = True ENABLED = True
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
ENABLED = False ENABLED = False
ndarray = None ndarray = None
np = None
class NumpyInterface(Interface): class NumpyInterface(Interface):
@ -41,7 +43,7 @@ class NumpyInterface(Interface):
return True return True
else: else:
try: try:
_ = ndarray(array) _ = np.array(array)
return True return True
except TypeError: except TypeError:
return False return False
@ -52,7 +54,7 @@ class NumpyInterface(Interface):
in :meth:`.check` in :meth:`.check`
""" """
if not isinstance(array, ndarray): if not isinstance(array, ndarray):
array = ndarray(array) array = np.array(array)
return array return array
@classmethod @classmethod