numpy / numpy/numpy

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

Open
#11,881 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

00 - Bug
Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

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)]

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue through numpy.round with an np.int64 value near the upper integer limit and a negative decimals value, then compare it with Python's round. Confirm the behavior across relevant negative decimal values and add regression coverage showing that rounding does not produce the incorrect wrapped result.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.