Repository: hgrecco/pint-pandas (language: python)

Issue:
pint-pandas-0.2: FAILED pint_pandas/testsuite/test_pandas_interface.py::TestMissing::test_fillna_no_op_returns_copy
For the record, trying to package pint-pandas for debian I end up with this error:

```
============================= test session starts ==============================
platform linux -- Python 3.9.9, pytest-6.2.5, py-1.10.0, pluggy-0.13.0
rootdir: /build/pint-pandas-0.2
plugins: subtests-0.5.0
collected 466 items

pint_pandas/testsuite/test_pandas_interface.py .......s....xxx.......... [  5%]
............................................................x........... [ 20%]
.....................xxxxxx............................................. [ 36%]
...................................................................xxxxx [ 51%]
xxxxxxxxxxxxxxxxxxxXXxx.xxxxxxxxxxxxxx..........................xxx..... [ 67%]
...F..................xx......................xXxXxxxXXXxXx............. [ 82%]
..............x.............................x........................... [ 98%]
.........                                                                [100%]

=================================== FAILURES ===================================
__________________ TestMissing.test_fillna_no_op_returns_copy __________________

self = <pint_pandas.testsuite.test_pandas_interface.TestMissing object at 0x7f721ba24100>
data = <PintArray>
[  1.0,   2.0,   3.0,   4.0,   5.0,   6.0,   7.0,   8.0,   9.0,  10.0,  11.0,
  12.0,  13.0,  14.0,  15.0,...89.0,  90.0,  91.0,  92.0,  93.0,  94.0,  95.0,  96.0,  97.0,  98.0,  99.0,
 100.0]
Length: 100, dtype: pint[nanometer]

    def test_fillna_no_op_returns_copy(self, data):
        data = data[~data.isna()]
    
        valid = data[0]
>       result = data.fillna(valid)

/usr/lib/python3/dist-packages/pandas/tests/extension/base/missing.py:89: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/lib/python3/dist-packages/pandas/core/arrays/base.py:721: in fillna
    value = missing.check_value_size(
/usr/lib/python3/dist-packages/pandas/core/missing.py:50: in check_value_size
    if len(value) != length:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <Quantity(1.0, 'nanometer')>

    def __len__(self) -> int:
>       return len(self._magnitude)
E       TypeError: object of type 'numpy.float64' has no len()

/usr/lib/python3/dist-packages/pint/quantity.py:1864: TypeError
=============================== warnings summary ===============================
pint_pandas/pint_array.py:194
  /build/pint-pandas-0.2/.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/pint_array.py:194: RuntimeWarning: pint-pandas does not support magnitudes of <class 'numpy.int64'>. Converting magnitudes to float.
    warnings.warn(

.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py: 220 warnings
  /build/pint-pandas-0.2/.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/pint_array.py:648: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
    return np.array(qtys, dtype="object", copy=copy)

.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py::TestGroupby::test_groupby_extension_apply[series]
  /usr/lib/python3/dist-packages/pandas/core/dtypes/cast.py:1997: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
    result[:] = values

.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py::TestGroupby::test_groupby_extension_apply[series]
.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py::TestMethods::test_shift_fill_value
  /usr/lib/python3/dist-packages/pandas/core/dtypes/missing.py:185: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
    return _isna_array(np.asarray(obj), inf_as_na=inf_as_na)

.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py::TestInterface::test_array_interface
  /usr/lib/python3/dist-packages/pandas/tests/extension/base/interface.py:67: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
    expected = np.array(list(data), dtype=object)

.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py: 13 warnings
  /usr/lib/python3/dist-packages/pandas/core/series.py:3118: UnitStrippedWarning: The unit of the quantity is stripped when downcasting to ndarray.
    new_values[:] = [func(lv, other) for lv in self._values]

.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py::TestSeriesAccessors::test_series_method_accessors[attr_args6]
  /build/pint-pandas-0.2/.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/pint_array.py:856: RuntimeWarning: to_compact applied to non numerical types has an undefined behavior.
    result = method(*args, **kwargs)

.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py::TestSeriesAccessors::test_series_method_accessors[attr_args6]
  /build/pint-pandas-0.2/.pybuild/cpython3_3.9_pint-pandas/build/pint_pandas/testsuite/test_pandas_interface.py:972: RuntimeWarning: to_compact applied to non numerical types has an undefined behavior.
    assert all(getattr(s.pint, attr)(*args) == getattr(data.quantity, attr)(*args))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
=========================== short test summary info ============================
FAILED pint_pandas/testsuite/test_pandas_interface.py::TestMissing::test_fillna_no_op_returns_copy

```

NB: I've tested the build with pint 0.18


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index af53585..3332470 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -8,7 +8,7 @@ jobs:
       matrix:
         python-version: [3.7, 3.8, 3.9]
         numpy: ["numpy>=1.14,<2.0.0"]
-        pandas: ["pandas==1.2"]
+        pandas: ["pandas==1.3"]
 
     runs-on: ubuntu-latest
 


Test patch:
diff --git a/pint_pandas/testsuite/test_pandas_interface.py b/pint_pandas/testsuite/test_pandas_interface.py
index 8b5093a..ddd4be0 100644
--- a/pint_pandas/testsuite/test_pandas_interface.py
+++ b/pint_pandas/testsuite/test_pandas_interface.py
@@ -617,6 +617,19 @@ def test_fillna_frame(self, data_missing):
         )
         self.assert_series_equal(result, expected)
 
+    @pytest.mark.xfail(run=True, reason="__iter__ / __len__ issue")
+    def test_fillna_no_op_returns_copy(self, data):
+        data = data[~data.isna()]
+
+        valid = data[0]
+        result = data.fillna(valid)
+        assert result is not data
+        self.assert_extension_array_equal(result, data)
+
+        result = data.fillna(method="backfill")
+        assert result is not data
+        self.assert_extension_array_equal(result, data)
+
 
 class TestNumericReduce(base.BaseNumericReduceTests):
     def check_reduce(self, s, op_name, skipna):