From dd9051c78476be2bc2cbf03ab895e8dde5ca14ca Mon Sep 17 00:00:00 2001 From: Warren Weckesser Date: Sun, 18 Aug 2019 12:07:55 -0400 Subject: BUG: core: Handle large negative np.int64 args in binary_repr. To avoid the cast to floating point that can occur when the first argument to binary_repr is a NumPy integer, the argument is converted to a Python integer at the beginning of the function. Closes gh-14289. --- numpy/core/numeric.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'numpy/core/numeric.py') diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index ff8c58867..bbcd58abb 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1935,6 +1935,10 @@ def binary_repr(num, width=None): "will raise an error in the future.", DeprecationWarning, stacklevel=3) + # Ensure that num is a Python integer to avoid overflow or unwanted + # casts to floating point. + num = operator.index(num) + if num == 0: return '0' * (width or 1) -- cgit v1.2.1