Repository: hgrecco/pint

Issue:
`round` doesn't convert the magnitude of a quantity to `int`
```py
>>> import pint; U = pint.UnitRegistry()
>>> round(1.1), type(round(1.1))
(1, <class 'int'>)
>>> round(1.1 * U.kg), type(round(1.1 * U.kg).magnitude)
(<Quantity(1.0, 'kilogram')>, <class 'float'>)
```

I'm not sure if this is a bug, but it certainly surprised me.

Discussion:
codspeed-hq[bot]: ## [CodSpeed Performance Report](https://codspeed.io/hgrecco/pint/branches/jules-ch%3Afix-round-function)

### Merging #2089 will **not alter performance**

<sub>Comparing <code>jules-ch:fix-round-function</code> (6deb749) with <code>master</code> (c70c076)</sub>



### Summary

`✅ 437` untouched benchmarks  





Patch:
diff --git a/CHANGES b/CHANGES
index 07328fb..e592ac1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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)
diff --git a/pint/facets/plain/quantity.py b/pint/facets/plain/quantity.py
index a189192..e70a02c 100644
--- a/pint/facets/plain/quantity.py
+++ b/pint/facets/plain/quantity.py
@@ -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
@@ -1288,8 +1288,8 @@ class PlainQuantity(Generic[MagnitudeT], PrettyIPython, SharedRegistryObject):
     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)


Test patch:
diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py
index 26a5ee0..6f17321 100644
--- a/pint/testsuite/test_quantity.py
+++ b/pint/testsuite/test_quantity.py
@@ -60,6 +60,11 @@ class TestQuantity(QuantityTestCase):
             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