Skip to content

Commit 6b0877a

Browse files
bors[bot]keewis
andauthored
Merge #951
951: ufunc calls with mixed args and upcast types r=hgrecco a=keewis This fixes an issue with calling ufuncs with mixed args including upcast types: Calling a bivariate ufunc like `np.maximum(da, 0 * ureg.m)` resulted in `pint` trying to work with upcast types because `__array_ufunc__` works with type objects while `is_upcast_type` checked object instances. - [x] Executed ``black -t py36 . && isort -rc . && flake8`` with no errors - [ ] The change is fully covered by automated unit tests Co-authored-by: Keewis <keewis@posteo.de>
2 parents 92fc293 + 6f1e41e commit 6b0877a

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

pint/compat.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ def _to_magnitude(value, force_ndarray=False):
147147

148148

149149
def is_upcast_type(other):
150+
""" check if the type object is a upcast type
151+
152+
:param other: type
153+
"""
150154
# Check if class name is in preset list
151-
return other.__class__.__name__ in ("PintArray", "Series", "DataArray")
155+
return other.__name__ in ("PintArray", "Series", "DataArray")
152156

153157

154158
def eq(first, second, check_all):

pint/quantity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def wrapped(self, *args, **kwargs):
9595
def check_implemented(f):
9696
def wrapped(self, *args, **kwargs):
9797
other = args[0]
98-
if is_upcast_type(other):
98+
if is_upcast_type(type(other)):
9999
return NotImplemented
100100
# pandas often gets to arrays of quantities [ Q_(1,"m"), Q_(2,"m")]
101101
# and expects Quantity * array[Quantity] should return NotImplemented

pint/testsuite/test_babel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_registry_locale(self):
4141
self.assertEqual(time.format_babel(locale="ro", length="short"), "8.0 s")
4242
acceleration = distance / time ** 2
4343
self.assertEqual(
44-
acceleration.format_babel(length="long"), "0.375 mètre par seconde²",
44+
acceleration.format_babel(length="long"), "0.375 mètre par seconde²"
4545
)
4646
mks = ureg.get_system("mks")
4747
self.assertEqual(mks.format_babel(locale="fr_FR"), "métrique")

0 commit comments

Comments
 (0)