Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
For reasons I have not fully determined, if you run the following:
HYPOTHESIS_DO_NOT_ESCALATE=true python -m pytest tests/numpy/test_gen_data.py -ktest_may_not_fill_with_non_nan_when_unique_is_set_and_type_is_not_number
You get the following error:
The confusion is not that this code fails with
The reason for this is that 'U' is something of a lie of a dtype. Consider the following code:
>>> import numpy as np >>> x = np.zeros(shape=1, dtype='U') >>> x array([''], dtype='<U1') >>> x = 'foo' >>> x array(['f'], dtype='<U1')
The 'U' dtype is actually a family of dtypes each of bounded width. When you create an array of unicode objects there's an implicit fixed sized limit on every element. As we create our arrays using
The same issue presumably exists with byte strings.
You can see this more directly by the fact that the following test passes but emits a pile of deprecation warnings:
from hypothesis import given from hypothesis.extra.numpy import arrays @given(arrays(shape=100, dtype='U')) def test_short(x): assert all(len(t) <= 1 for t in x)
True! I've only tested this on Python 3. Though given that we're in the dying days of Python 2 support if it presents much trouble we may just want to wait on fixing this until January...