Repository: HypothesisWorks/hypothesis

Issue:
test_can_turn_off_subarrays  is flaky
Every now and then I see the following error from it:

```
570, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
ValueError: field 'f1' occurs more than once
```

For example here: https://travis-ci.org/HypothesisWorks/hypothesis/jobs/489245732#L1288

In this example it's on Python 2 but I don't know whether that's essential.


Discussion:
I've never seen this in the two months since #1803.  Yay heisenbugs I guess?
Closing this as I can't reproduce it and haven't seen it since #1803.
We finally saw this [happen on Windows 64bit, Python 2.7](https://dev.azure.com/HypothesisWorks/Hypothesis/_build/results?buildId=2035)!

```
_________________________ test_np_dtype_is_idempotent _________________________
Traceback (most recent call last):
  ...
ValueError: field 'f3' occurs more than once
---------------------------- Captured stdout call -----------------------------
Got invalid dtype value=[('\xfe\xfe\x84X', dtype('>m8[ns]')), ('\xd0\xb1%`$\x08\t@\xb4C4\xdf\xecJ\xfe\xfc\x9e0', dtype('>c8')), ('f3', dtype('<M8[M]')), ('', dtype('float64')), ('W\xaaB\xfb\xa7\x1b', dtype('>u2'), (2, 1))] from strategy=lists(elements=one_of(tuples(binary(), <hypothesis.searchstrategy.recursive.LimitedStrategy at 0x1324c128>), tuples(binary(), <hypothesis.searchstrategy.recursive.LimitedStrategy at 0x1324c128>, array_shapes(max_dims=2, max_side=2))), min_size=1, max_size=5, unique_by=lambda d: d[0]), function=<function array_dtypes at 0x0000000008B7A128>
--------------------------------- Hypothesis ----------------------------------
You can add @seed(315459762023301249284010228506111077501) to this test or run pytest with --hypothesis-seed=315459762023301249284010228506111077501 to reproduce this failure.
```

<details>

```python-traceback
  File "D:\a\1\s\hypothesis-python\tests\numpy\test_gen_data.py", line 214, in test_np_dtype_is_idempotent
    def test_np_dtype_is_idempotent(dtype):
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\core.py", line 987, in wrapped_test
    state.run()
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\core.py", line 660, in run
    runner.run()
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\engine.py", line 398, in run
    self._run()
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\engine.py", line 769, in _run
    self.generate_new_examples()
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\engine.py", line 753, in generate_new_examples
    self.test_function(data)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\engine.py", line 144, in test_function
    self.__stoppable_test_function(data)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\engine.py", line 127, in __stoppable_test_function
    self._test_function(data)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\core.py", line 626, in evaluate_test_data
    escalate_hypothesis_internal_error()
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\core.py", line 606, in evaluate_test_data
    result = self.execute(data)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\core.py", line 571, in execute
    result = self.test_runner(data, run)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\executors.py", line 56, in default_new_style_executor
    return function(data)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\core.py", line 550, in run
    args, kwargs = data.draw(self.search_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 849, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\collections.py", line 59, in do_draw
    return tuple(data.draw(e) for e in self.element_strategies)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\collections.py", line 59, in <genexpr>
    return tuple(data.draw(e) for e in self.element_strategies)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 560, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\lazy.py", line 156, in do_draw
    return data.draw(self.wrapped_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 560, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\collections.py", line 59, in do_draw
    return tuple(data.draw(e) for e in self.element_strategies)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\collections.py", line 59, in <genexpr>
    return tuple(data.draw(e) for e in self.element_strategies)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\lazy.py", line 156, in do_draw
    return data.draw(self.wrapped_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 636, in do_draw
    data=data, filter_strategy=self
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 356, in do_filtered_draw
    return filter_strategy.default_do_filtered_draw(data)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 651, in default_do_filtered_draw
    value = data.draw(self.filtered_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\recursive.py", line 100, in do_draw
    return data.draw(self.strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 498, in do_draw
    return data.draw(self.element_strategies[i], label=self.branch_labels[i])
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\lazy.py", line 156, in do_draw
    return data.draw(self.wrapped_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 560, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\lazy.py", line 156, in do_draw
    return data.draw(self.wrapped_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\collections.py", line 160, in do_draw
    data=data, filter_strategy=filtered
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 356, in do_filtered_draw
    return filter_strategy.default_do_filtered_draw(data)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 651, in default_do_filtered_draw
    value = data.draw(self.filtered_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 498, in do_draw
    return data.draw(self.element_strategies[i], label=self.branch_labels[i])
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\lazy.py", line 156, in do_draw
    return data.draw(self.wrapped_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\collections.py", line 59, in do_draw
    return tuple(data.draw(e) for e in self.element_strategies)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\collections.py", line 59, in <genexpr>
    return tuple(data.draw(e) for e in self.element_strategies)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 498, in do_draw
    return data.draw(self.element_strategies[i], label=self.branch_labels[i])
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\lazy.py", line 156, in do_draw
    return data.draw(self.wrapped_strategy)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 834, in draw
    return self.__draw(strategy, label=label)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\internal\conjecture\data.py", line 843, in __draw
    return strategy.do_draw(self)
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\searchstrategy\strategies.py", line 560, in do_draw
    result = self.pack(data.draw(self.mapped_strategy))
  File "c:\hostedtoolcache\windows\python\2.7.14\x64\lib\site-packages\hypothesis\extra\numpy.py", line 457, in convert_to_dtype
    return np.dtype(x)
```

</details>

I'll update with more details as they come.

Resolving patch:
diff --git a/hypothesis-python/src/hypothesis/extra/numpy.py b/hypothesis-python/src/hypothesis/extra/numpy.py
--- a/hypothesis-python/src/hypothesis/extra/numpy.py
+++ b/hypothesis-python/src/hypothesis/extra/numpy.py
@@ -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, text_type
+from hypothesis.internal.compat import 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
@@ -636,9 +636,7 @@ 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.text()  # type: SearchStrategy[Any]
-    if text_type is not str:  # pragma: no cover
-        native_strings = st.binary()
+    native_strings = st.from_type(str).filter(bool)  # See issue #1798 re: filter!
     elements = st.tuples(native_strings, subtype_strategy)
     if allow_subarrays:
         elements |= st.tuples(


Test patch: