Skip to content

Commit

Permalink
Parameterized dtypes are not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
jobh committed Jun 8, 2023
1 parent ffaa011 commit ef90ea2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 3 additions & 4 deletions hypothesis-python/RELEASE.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
RELEASE_TYPE: minor

Implement support for :func:`hypothesis.strategies.from_type` to handle generic numpy types (such
as :class:`numpy.typing.ArrayLike`) and parameterized numpy arrays (such as
:class:`numpy.ndarray[scalar type] <numpy.ndarray>` or
:class:`numpy.typing.NDArray[scalar type] <numpy.typing.NDArray>`). This closes :issue:`3150`.
Implement support for :func:`hypothesis.strategies.from_type` to handle generic
and parameterized numpy array types (:class:`numpy.ndarray[scalar type] <numpy.ndarray>`,
numpy.typing.ArrayLike, etc).
10 changes: 8 additions & 2 deletions hypothesis-python/src/hypothesis/extra/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def _try_import(mod_name: str, attr_name: str) -> Any:
if TYPE_CHECKING:
from numpy.typing import DTypeLike, NDArray
else:
DTypeLike = _try_import("numpy.typing", "DTypeLike")
NDArray = _try_import("numpy.typing", "NDArray")

ArrayLike = _try_import("numpy.typing", "ArrayLike")
Expand Down Expand Up @@ -1073,7 +1072,14 @@ def _from_type(thing: Type[Ex]) -> Optional[st.SearchStrategy[Ex]]:
)

if thing == np.dtype:
return array_dtypes()
# Note: Parameterized dtypes and DTypeLike are not supported.
return st.one_of(
scalar_dtypes(),
byte_string_dtypes(),
unicode_string_dtypes(),
array_dtypes(),
nested_dtypes(),
)

if thing == ArrayLike:
# We override the default type resolution to ensure the "coercible to
Expand Down

0 comments on commit ef90ea2

Please sign in to comment.