Skip to content

Commit

Permalink
Explict Pandas error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Nov 14, 2022
1 parent 6051b07 commit b4a2eb1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions hypothesis-python/src/hypothesis/extra/pandas/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ def elements_and_dtype(elements, dtype, source=None):
has_codemod=False,
)

if isinstance(dtype, st.SearchStrategy):
raise InvalidArgument(
f"Passed dtype={dtype!r} is a strategy, but we require a concrete dtype "
"here. See https://stackoverflow.com/q/74355937 for workaround patterns."
)
dtype = try_convert(np.dtype, dtype, "dtype")

if elements is None:
Expand Down Expand Up @@ -532,9 +537,8 @@ def row():
hash(c.name)
except TypeError:
raise InvalidArgument(
"Column names must be hashable, but columns[%d].name was "
"%r of type %s, which cannot be hashed."
% (i, c.name, type(c.name).__name__)
f"Column names must be hashable, but columns[{i}].name was "
f"{c.name!r} of type {type(c.name).__name__}, which cannot be hashed."
) from None

if c.name in column_names:
Expand Down
1 change: 1 addition & 0 deletions hypothesis-python/tests/pandas/test_argument_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
e(pdst.indexes, elements="not a strategy"),
e(pdst.indexes, elements=st.text(), dtype=float),
e(pdst.indexes, elements=st.none(), dtype=int),
e(pdst.indexes, elements=st.integers(0, 10), dtype=st.sampled_from([int, float])),
e(pdst.indexes, dtype=int, max_size=0, min_size=1),
e(pdst.indexes, dtype=int, unique="true"),
e(pdst.indexes, dtype=int, min_size="0"),
Expand Down

0 comments on commit b4a2eb1

Please sign in to comment.