Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Pint Changelog
-------------------

- Add docs to the functions in ``pint.testing`` (PR #2070)
- Fix round function returning float instead of int (#2081)


0.24.4 (2024-11-07)
Expand Down
12 changes: 6 additions & 6 deletions pint/facets/plain/quantity.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""
pint.facets.plain.quantity
~~~~~~~~~~~~~~~~~~~~~~~~~
pint.facets.plain.quantity
~~~~~~~~~~~~~~~~~~~~~~~~~

:copyright: 2022 by Pint Authors, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
:copyright: 2022 by Pint Authors, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from __future__ import annotations
Expand Down Expand Up @@ -1288,8 +1288,8 @@ def __rpow__(self, other) -> PlainQuantity[MagnitudeT]:
def __abs__(self) -> PlainQuantity[MagnitudeT]:
return self.__class__(abs(self._magnitude), self._units)

def __round__(self, ndigits: int | None = 0) -> PlainQuantity[MagnitudeT]:
return self.__class__(round(self._magnitude, ndigits=ndigits), self._units)
def __round__(self, ndigits: int | None = None) -> PlainQuantity[int]:
return self.__class__(round(self._magnitude, ndigits), self._units)

def __pos__(self) -> PlainQuantity[MagnitudeT]:
return self.__class__(operator.pos(self._magnitude), self._units)
Expand Down
5 changes: 5 additions & 0 deletions pint/testsuite/test_quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def test_quantity_creation(self, caplog):
assert 4.2 * self.ureg.meter == self.Q_(4.2, 2 * self.ureg.meter)
assert len(caplog.records) == 1

def test_round(self):
x = self.Q_(1.1, "kg")
assert isinstance(round(x).magnitude, int)
assert isinstance(round(x, 0).magnitude, float)

def test_quantity_with_quantity(self):
x = self.Q_(4.2, "m")
assert self.Q_(x, "m").magnitude == 4.2
Expand Down