Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return bools from array_function #264

Merged
merged 4 commits into from
Dec 29, 2024
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
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
Loading