BUG: np.round on int64/uint64 with negative decimals loses precision

Offen
#33,461 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
numpy, python
Bereich
data

Rechercherichtung

Start by tracing NumPy's rounding implementation for integer arrays with negative decimals and inspect the relevant tests; the issue does not name specific files. Reproduce the examples for int64 and uint64 values above 2^53, then check that rounded results are exact multiples of the requested power of ten and match Python's integer rounding.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

00 - Bug
Describe the issue:
  • For integer input with negative decimals, the result isn't a multiple of $10^k$.
  • Values above $2^{53}$ are affected because the computation goes through float64.
  • What i'd expect: an exact integer result.
Reproduce the code example:
import numpy as np

ts = np.array([1_700_000_000_123_456_789], dtype=np.int64)
print(np.round(ts, -3))         # [1700000000123457024]
print(round(int(ts[0]), -3))    # 1700000000123457000

print(np.round(np.array([2**63 + 7], dtype=np.uint64), -1))  # [9223372036854775808]
Error message:

I expect an error or at least a warning if not a fix.

Python and NumPy Versions:

numpy - 2.5.5
python - 3.14.10

Runtime Environment:

No response

How does this issue affect you or how did you find it:
  • How did I find it: We store event timestamps as microseconds in our postgres. However the source data is in ns timestamps, for an aligning and deduplication purpose we need to round it to microseconds.

  • How does this issue affect me: np.round() returns many values mismatch.

Vorherrschende Sprache
Python
Sterne
33.5k
Forks
13.1k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
143

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus numpy/numpy

Alle Issues in numpy/numpy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.