MCPcopy
hub / github.com/pytest-dev/pytest / _as_numpy_array

Function _as_numpy_array

src/_pytest/python_api.py:908–922  ·  view source on GitHub ↗

Return an ndarray if the given object is implicitly convertible to ndarray, and numpy is already imported, otherwise None.

(obj: object)

Source from the content-addressed store, hash-verified

906
907
908def _as_numpy_array(obj: object) -> ndarray | None:
909 """
910 Return an ndarray if the given object is implicitly convertible to ndarray,
911 and numpy is already imported, otherwise None.
912 """
913 np: Any = sys.modules.get("numpy")
914 if np is not None:
915 # avoid infinite recursion on numpy scalars, which have __array__
916 if np.isscalar(obj):
917 return None
918 elif isinstance(obj, np.ndarray):
919 return obj
920 elif hasattr(obj, "__array__") or hasattr(obj, "__array_interface__"):
921 return np.asarray(obj)
922 return None

Callers 3

_repr_compareMethod · 0.85
__eq__Method · 0.85
approxFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected