Skip to content

Commit

Permalink
More efficient field names
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Sep 9, 2019
1 parent f0cf20f commit 40b3a9e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions hypothesis-python/src/hypothesis/extra/numpy.py
Expand Up @@ -26,7 +26,7 @@
from hypothesis import Verbosity
from hypothesis._settings import note_deprecation
from hypothesis.errors import InvalidArgument
from hypothesis.internal.compat import hrange, integer_types
from hypothesis.internal.compat import PY2, hrange, integer_types
from hypothesis.internal.coverage import check_function
from hypothesis.internal.reflection import proxies
from hypothesis.internal.validation import check_type, check_valid_interval
Expand Down Expand Up @@ -615,11 +615,15 @@ def array_dtypes(
"""Return a strategy for generating array (compound) dtypes, with members
drawn from the given subtype strategy."""
order_check("size", 0, min_size, max_size)
native_strings = st.from_type(str).filter(bool) # See issue #1798 re: filter!
elements = st.tuples(native_strings, subtype_strategy)
# Field names must be native strings and the empty string is weird; see #1963.
if PY2:
field_names = st.bytes(min_size=1)
else:
field_names = st.text(min_size=1)
elements = st.tuples(field_names, subtype_strategy)
if allow_subarrays:
elements |= st.tuples(
native_strings, subtype_strategy, array_shapes(max_dims=2, max_side=2)
field_names, subtype_strategy, array_shapes(max_dims=2, max_side=2)
)
return st.lists(
elements=elements,
Expand Down

0 comments on commit 40b3a9e

Please sign in to comment.