Skip to content

Commit 77914f8

Browse files
authored
Merge pull request #3946 from Zac-HD/numpy-nat
Allow excluding `NaT`
2 parents 15ae3c2 + e6567e5 commit 77914f8

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

hypothesis-python/RELEASE.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
RELEASE_TYPE: minor
2+
3+
The :func:`~hypothesis.extra.numpy.from_dtype` function no longer generates
4+
``NaT`` ("not-a-time") values for the ``datetime64`` or ``timedelta64`` dtypes
5+
if passed ``allow_nan=False`` (:issue:`3943`).

hypothesis-python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def local_file(name):
6060
"pytest": ["pytest>=4.6"],
6161
"dpcontracts": ["dpcontracts>=0.4"],
6262
"redis": ["redis>=3.0.0"],
63-
"crosshair": ["hypothesis-crosshair>=0.0.2", "crosshair-tool>=0.0.53"],
63+
"crosshair": ["hypothesis-crosshair>=0.0.2", "crosshair-tool>=0.0.54"],
6464
# zoneinfo is an odd one: every dependency is conditional, because they're
6565
# only necessary on old versions of Python or Windows systems or emscripten.
6666
"zoneinfo": [

hypothesis-python/src/hypothesis/extra/numpy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,11 @@ def compat_kw(*args, **kw):
219219
# it here because we'd have to guard against equivalents in arrays()
220220
# regardless and drawing scalars is a valid use-case.
221221
res = st.sampled_from(TIME_RESOLUTIONS)
222-
result = st.builds(dtype.type, st.integers(-(2**63), 2**63 - 1), res)
222+
if allow_nan is not False:
223+
elems = st.integers(-(2**63), 2**63 - 1) | st.just("NaT")
224+
else: # NEP-7 defines the NaT value as integer -(2**63)
225+
elems = st.integers(-(2**63) + 1, 2**63 - 1)
226+
result = st.builds(dtype.type, elems, res)
223227
else:
224228
raise InvalidArgument(f"No strategy inference for {dtype}")
225229
return result.map(dtype.type)

hypothesis-python/src/hypothesis/vendor/tlds-alpha-by-domain.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Version 2024031000, Last Updated Sun Mar 10 07:07:01 2024 UTC
1+
# Version 2024033000, Last Updated Sat Mar 30 07:07:01 2024 UTC
22
AAA
33
AARP
44
ABB
@@ -85,7 +85,6 @@ AUSPOST
8585
AUTHOR
8686
AUTO
8787
AUTOS
88-
AVIANCA
8988
AW
9089
AWS
9190
AX

hypothesis-python/tests/numpy/test_from_dtype.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,13 @@ def test_arrays_selects_consistent_time_unit(data, dtype_str):
181181
assert (dtype_str + "[") in arr.dtype.str
182182

183183

184+
@pytest.mark.parametrize("dtype", ["m8", "M8"])
185+
def test_from_dtype_can_include_or_exclude_nat(dtype):
186+
find_any(nps.from_dtype(np.dtype(dtype), allow_nan=None), np.isnat)
187+
find_any(nps.from_dtype(np.dtype(dtype), allow_nan=True), np.isnat)
188+
assert_no_examples(nps.from_dtype(np.dtype(dtype), allow_nan=False), np.isnat)
189+
190+
184191
def test_arrays_gives_useful_error_on_inconsistent_time_unit():
185192
with pytest.raises(InvalidArgument, match="mismatch of time units in dtypes"):
186193
check_can_generate_examples(

0 commit comments

Comments
 (0)