Skip to content

Commit e1e585b

Browse files
committed
handle overflow in validation
1 parent eba9c12 commit e1e585b

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

hypothesis-python/RELEASE.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RELEASE_TYPE: patch
2+
3+
Improves input validation for several strategies in our :ref:`pandas extra
4+
<hypothesis-pandas>`, so that they raise a helpful ``InvalidArgument`` rather
5+
than ``OverflowError``.
6+
7+
Discovered by our recent :ref:`string generation upgrade <v6.128.0>`.

hypothesis-python/src/hypothesis/extra/pandas/impl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def convert_element(value):
128128
name = f"draw({prefix}elements)"
129129
try:
130130
return np.array([value], dtype=dtype)[0]
131-
except (TypeError, ValueError):
131+
except (TypeError, ValueError, OverflowError):
132132
raise InvalidArgument(
133133
"Cannot convert %s=%r of type %s to dtype %s"
134134
% (name, value, type(value).__name__, dtype.str)

hypothesis-python/tests/pandas/test_argument_validation.py

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
marks=pytest.mark.skipif(IntegerDtype, reason="works with integer NA"),
7979
),
8080
e(pdst.indexes, elements=st.text(), dtype=int),
81+
e(pdst.indexes, elements=st.just("9" * 30), dtype=int), # OverflowError handling
8182
e(pdst.indexes, elements=st.integers(0, 10), dtype=st.sampled_from([int, float])),
8283
e(pdst.indexes, dtype=int, max_size=0, min_size=1),
8384
e(pdst.indexes, dtype=int, unique="true"),

0 commit comments

Comments
 (0)