Skip to content

Commit

Permalink
return bools from array_function
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage committed Dec 29, 2024
1 parent d1eb38d commit a94d678
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pint_pandas/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
return self._convert_np_result(result)

def _convert_np_result(self, result):
if isinstance(result, bool):
return result
if isinstance(result, _Quantity) and is_list_like(result.m):
return PintArray.from_1darray_quantity(result)
elif isinstance(result, _Quantity):
Expand Down
24 changes: 24 additions & 0 deletions pint_pandas/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,27 @@ def test_issue246(self):

# now an operation where each cell is independent from each other
df.apply(lambda x: x * 2, axis=1)
<<<<<<< Updated upstream
=======


class TestArrayFunction(BaseExtensionTests):
def test_issue255(self):
a = np.r_[1, 2, np.nan, 4, 10]
pa = PintArray.from_1darray_quantity(a * ureg.m)

result = np.clip(pa, 3 * ureg.m, 5 * ureg.m)

e = np.clip(a, 3, 5)
expected = PintArray.from_1darray_quantity(e * ureg.m)

tm.assert_equal(result, expected)

def test_issue108(self):
pa1 = pa2 = PintArray([1, 45, -4.5], 'm')

result = np.allclose(pa1, pa2)
expected = True

assert result == expected
>>>>>>> Stashed changes

0 comments on commit a94d678

Please sign in to comment.