Skip to content

Commit

Permalink
return bools from array_function (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgsavage authored Dec 29, 2024
1 parent 974cb2f commit 32626b1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pint_pandas/pint_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,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):
if hasattr(result, "ndim") and result.ndim >= 2:
raise ValueError("PintArrays may only be 1D, check axis arguement")
Expand Down
10 changes: 9 additions & 1 deletion pint_pandas/testsuite/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def test_issue246(self):
df.apply(lambda x: x * 2, axis=1)


class TestIssue255(BaseExtensionTests):
class TestArrayFunction(BaseExtensionTests):
def test_issue255(self):
a = np.r_[1, 2, np.nan, 4, 10]
pa = PintArray.from_1darray_quantity(a * ureg.m)
Expand All @@ -324,3 +324,11 @@ def test_issue255(self):
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

0 comments on commit 32626b1

Please sign in to comment.