Skip to content

numpy.round(i, decimals=d) wrong for np.int64 and d<0 #11881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
miccoli opened this issue Sep 4, 2018 · 3 comments
Open

numpy.round(i, decimals=d) wrong for np.int64 and d<0 #11881

miccoli opened this issue Sep 4, 2018 · 3 comments
Labels

Comments

@miccoli
Copy link
Contributor

miccoli commented Sep 4, 2018

numpy.round returns wrong value when decimals are negative and argument is np.int64

Reproducing code example:

>>> import numpy as np
>>> np.round(2**63-1, -3)
-9223372036854775808
>>> round(2**63-1, -3)
9223372036854776000

Numpy/Python version information:

>>> import sys, numpy; print(numpy.__version__, sys.version)
1.15.1 3.6.5 (default, Apr  5 2018, 23:36:52) 
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
@eric-wieser
Copy link
Member

Caused by np.ndarray.round using floats internally

@miccoli
Copy link
Contributor Author

miccoli commented Nov 23, 2022

Re: Closember
this issue is still active at

>>> import sys, numpy; print(numpy.__version__, sys.version)
1.23.5 3.10.4 (main, Jun  9 2022, 14:49:07) [Clang 13.0.0 (clang-1300.0.29.30)]
>>> numpy.around([2**63-1], -3)
array([-9223372036854775808])
>>> numpy.array([round(2**63-1, -3)])
array([9223372036854776000], dtype=uint64)

@Taiquan-Liu
Copy link

We had problems when using numpy.round to a numpy.int64 object. Using Python round and pandas.Int64Dtype instead seems to fix the problem for us. Running some benchmark shows the two methods use similar amount of time across some of our test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants