mirror of
https://github.com/p2p-ld/numpydantic.git
synced 2024-11-10 00:34:29 +00:00
use np.array rather than ndarray to coerce lists
This commit is contained in:
parent
5e90c1bee1
commit
9c41705883
1 changed files with 4 additions and 2 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue