Repository: hgrecco/pint-pandas

Issue:
`numpy.allclose` not working for `PintArray`
# Issue 

```python
import pandas as pd
import numpy as np
from pint_pandas import PintArray

>>> pa1 = pa2 = PintArray([1, 45, -4.5], 'm')
>>> np.allclose(pa1, pa2)


# ---------------------------------------------------------------------------
# TypeError                                 Traceback (most recent call last)
#       16 pa = PintArray([1, 45, -4.5], 'm')
# ----> 17 np.allclose(pa1, pa2)

# <__array_function__ internals> in allclose(*args, **kwargs)

# ~\Anaconda3\envs\lb38\lib\site-packages\numpy\core\numeric.py in allclose(a, b, rtol, atol, equal_nan)
#    2248     """
# -> 2249     res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
#    2250     return bool(res)

# <__array_function__ internals> in isclose(*args, **kwargs)

# ~\Anaconda3\envs\lb38\lib\site-packages\numpy\core\numeric.py in isclose(a, b, rtol, atol, equal_nan)
#    2354 
# -> 2355     xfin = isfinite(x)
#    2356     yfin = isfinite(y)

# TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
```

I'm on `pint` version 0.18 and `pint_pandas` 0.2



# Non-complete workaround
```python
>>> pa1.quantity.units == pa2.quantity.units and np.allclose(pa1.quantity.m, pa2.quantity.m)
True
```
This is not watertight! Workaround incorrectly returns `False` when comparing 1 m with 100 cm.

# Watertight (?) workaround
```python

def pintarray_allclose(pa1, pa2):
    if pa1.quantity.dimensionality != pa2.quantity.dimensionality:
        return False
    a1 = pa1.quantity.magnitude
    a2 = pa2.astype(f"pint[{pa1.quantity.units}]").quantity.magnitude
    return np.allclose(a1, a2)

>>> pintarray_allclose(pa1, pa2)
True

>>> pintarray_allclose(pa1, pa2.astype('pint[km]'))
True
```



Discussion:

Patch:
diff --git a/pint_pandas/pint_array.py b/pint_pandas/pint_array.py
index df5ed65..082071e 100644
--- a/pint_pandas/pint_array.py
+++ b/pint_pandas/pint_array.py
@@ -350,6 +350,8 @@ class PintArray(ExtensionArray, ExtensionScalarOpsMixin):
         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")


Test patch:
diff --git a/pint_pandas/testsuite/test_issues.py b/pint_pandas/testsuite/test_issues.py
index 3ea07eb..19b224a 100644
--- a/pint_pandas/testsuite/test_issues.py
+++ b/pint_pandas/testsuite/test_issues.py
@@ -313,7 +313,7 @@ class TestIssue246(BaseExtensionTests):
         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)
@@ -324,3 +324,11 @@ class TestIssue255(BaseExtensionTests):
         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