diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2021-02-18 00:24:02 -0500 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2021-02-18 09:18:56 -0500 |
commit | 4de12597c1f15fad33201aea2cc918a687c20665 (patch) | |
tree | d8a061ed57d9c03afe0f9cf1344cb77872b9b497 | |
parent | 0eb9f54e5e466c8d7a76ae116712b368d045c7e0 (diff) | |
download | numpy-4de12597c1f15fad33201aea2cc918a687c20665.tar.gz |
MAINT: random: Use 'from None' when raising a ValueError in choice.
Use 'from None' when the ValueError is raised when the first argument to
`choice` is not an array and not an integer.
Also fix the error message for the ValueError, and add a missing space
to two other error messages.
-rw-r--r-- | numpy/random/_generator.pyx | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/numpy/random/_generator.pyx b/numpy/random/_generator.pyx index a7d98e2ed..b246037f1 100644 --- a/numpy/random/_generator.pyx +++ b/numpy/random/_generator.pyx @@ -694,21 +694,23 @@ cdef class Generator: cdef uint64_t set_size, mask cdef uint64_t[::1] hash_set # Format and Verify input + a_original = a a = np.array(a, copy=False) if a.ndim == 0: try: # __index__ must return an integer by python rules. pop_size = operator.index(a.item()) except TypeError: - raise ValueError("a must an array or an integer") + raise ValueError("a must be an array or an integer, " + f"not {type(a_original)}") from None if pop_size <= 0 and np.prod(size) != 0: raise ValueError("a must be a positive integer unless no" - "samples are taken") + " samples are taken") else: pop_size = a.shape[axis] if pop_size == 0 and np.prod(size) != 0: raise ValueError("a cannot be empty unless no samples are" - "taken") + " taken") if p is not None: d = len(p) |