Bug#944267: pandas: patches for numpy 1.17 compatibility

Michael Hudson-Doyle michael.hudson at ubuntu.com
Thu Nov 7 02:18:17 GMT 2019


Source: pandas
Version: 0.23.3+dfsg-4
Severity: normal
Tags: patch

Dear Maintainer,

To aid with the entangled numpy / python 3.8 / everything transition in
Ubuntu I cooked up some patches that make pandas 0.23.3 pass tests with
numpy 1.17, attached in case they would be useful in Debian too. They
actually break with 1.16 unfortunately but that would probably be quite
easy to fix.

Cheers,
mwh
-- System Information:
Debian Release: buster/sid
  APT prefers eoan-updates
  APT policy: (500, 'eoan-updates'), (500, 'eoan'), (400, 'eoan-proposed'), (100, 'eoan-backports')
Architecture: amd64 (x86_64)

Kernel: Linux 5.3.0-19-generic (SMP w/8 CPU cores)
Kernel taint flags: TAINT_PROPRIETARY_MODULE, TAINT_OOT_MODULE
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
-------------- next part --------------
diff -Nru pandas-0.23.3+dfsg/debian/changelog pandas-0.23.3+dfsg/debian/changelog
--- pandas-0.23.3+dfsg/debian/changelog	2019-10-22 16:11:08.000000000 +0000
+++ pandas-0.23.3+dfsg/debian/changelog	2019-11-06 00:15:32.000000000 +0000
@@ -1,3 +1,10 @@
+pandas (0.23.3+dfsg-4ubuntu6) focal; urgency=medium
+
+  * Backport some fixes for compatibility with numpy 1.17+.
+  * Stop ignoring test results on Python 3.7.
+
+ -- Michael Hudson-Doyle <michael.hudson at ubuntu.com>  Wed, 06 Nov 2019 13:15:32 +1300
+
 pandas (0.23.3+dfsg-4ubuntu5) focal; urgency=medium
 
   * Fix installation for multiple python3 versions.
diff -Nru pandas-0.23.3+dfsg/debian/patches/COMPAT-Compat-with-numpy-dev-argsort-radix-sort-adde.patch pandas-0.23.3+dfsg/debian/patches/COMPAT-Compat-with-numpy-dev-argsort-radix-sort-adde.patch
--- pandas-0.23.3+dfsg/debian/patches/COMPAT-Compat-with-numpy-dev-argsort-radix-sort-adde.patch	1970-01-01 00:00:00.000000000 +0000
+++ pandas-0.23.3+dfsg/debian/patches/COMPAT-Compat-with-numpy-dev-argsort-radix-sort-adde.patch	2019-11-06 00:15:32.000000000 +0000
@@ -0,0 +1,32 @@
+Description: backport numpy 1.17 compat
+  This is a manual backport of https://github.com/pandas-dev/pandas/commit/a6e43a43f2cb1b4b7d46b262be2efb825d033eb8
+Bug: https://github.com/pandas-dev/pandas/issues/26361
+Applied-Upstream: a6e43a43f2cb1b4b7d46b262be2efb825d033eb8
+Last-Update: 2019-11-06
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+--- a/pandas/compat/numpy/function.py
++++ b/pandas/compat/numpy/function.py
+@@ -18,7 +18,8 @@
+ easier to adjust to future upstream changes in the analogous numpy signatures.
+ """
+ 
+-from numpy import ndarray
++from distutils.version import LooseVersion
++from numpy import __version__ as _np_version, ndarray
+ from pandas.util._validators import (validate_args, validate_kwargs,
+                                      validate_args_and_kwargs)
+ from pandas.errors import UnsupportedFunctionCall
+@@ -112,6 +113,12 @@
+ ARGSORT_DEFAULTS_KIND = OrderedDict()
+ ARGSORT_DEFAULTS_KIND['axis'] = -1
+ ARGSORT_DEFAULTS_KIND['order'] = None
++
++if LooseVersion(_np_version) >= LooseVersion("1.17.0"):
++    # GH-26361. NumPy added radix sort and changed default to None.
++    ARGSORT_DEFAULTS['kind'] = None
++
++
+ validate_argsort_kind = CompatValidator(ARGSORT_DEFAULTS_KIND, fname='argsort',
+                                         max_fname_arg_count=0, method='both')
+ 
diff -Nru pandas-0.23.3+dfsg/debian/patches/series pandas-0.23.3+dfsg/debian/patches/series
--- pandas-0.23.3+dfsg/debian/patches/series	2019-09-16 08:29:53.000000000 +0000
+++ pandas-0.23.3+dfsg/debian/patches/series	2019-11-06 00:15:32.000000000 +0000
@@ -30,3 +30,6 @@
 array_series_matmul.patch
 pytest_fixtures.patch
 skip_noencoding_locales.patch
+COMPAT-Compat-with-numpy-dev-argsort-radix-sort-adde.patch
+TST-parameterize-indexes-base-test-to-introspect-ufu.patch
+test_add_timestamp_raises.patch
diff -Nru pandas-0.23.3+dfsg/debian/patches/test_add_timestamp_raises.patch pandas-0.23.3+dfsg/debian/patches/test_add_timestamp_raises.patch
--- pandas-0.23.3+dfsg/debian/patches/test_add_timestamp_raises.patch	1970-01-01 00:00:00.000000000 +0000
+++ pandas-0.23.3+dfsg/debian/patches/test_add_timestamp_raises.patch	2019-11-06 00:15:32.000000000 +0000
@@ -0,0 +1,12 @@
+--- a/pandas/tests/scalar/period/test_period.py
++++ b/pandas/tests/scalar/period/test_period.py
+@@ -1050,7 +1050,8 @@
+         # the error.
+         msg = (r"cannot add|unsupported operand|"
+                r"can only operate on a|incompatible type|"
+-               r"ufunc add cannot use operands")
++               r"ufunc add cannot use operands|"
++               r"ufunc 'add' cannot use operands")
+         with tm.assert_raises_regex(TypeError, msg):
+             lbox(ts) + rbox(per)
+ 
diff -Nru pandas-0.23.3+dfsg/debian/patches/TST-parameterize-indexes-base-test-to-introspect-ufu.patch pandas-0.23.3+dfsg/debian/patches/TST-parameterize-indexes-base-test-to-introspect-ufu.patch
--- pandas-0.23.3+dfsg/debian/patches/TST-parameterize-indexes-base-test-to-introspect-ufu.patch	1970-01-01 00:00:00.000000000 +0000
+++ pandas-0.23.3+dfsg/debian/patches/TST-parameterize-indexes-base-test-to-introspect-ufu.patch	2019-11-06 00:15:32.000000000 +0000
@@ -0,0 +1,156 @@
+--- a/pandas/tests/indexes/common.py
++++ b/pandas/tests/indexes/common.py
+@@ -7,7 +7,7 @@
+ 
+ import numpy as np
+ 
+-from pandas import (Series, Index, Float64Index, Int64Index, UInt64Index,
++from pandas import (Series, Index, Int64Index, UInt64Index,
+                     RangeIndex, MultiIndex, CategoricalIndex, DatetimeIndex,
+                     TimedeltaIndex, PeriodIndex, IntervalIndex, isna)
+ from pandas.core.indexes.base import InvalidIndexError
+@@ -819,59 +819,6 @@
+             tm.assert_numpy_array_equal(index_a == item, expected3)
+             tm.assert_series_equal(series_a == item, Series(expected3))
+ 
+-    def test_numpy_ufuncs(self):
+-        # test ufuncs of numpy 1.9.2. see:
+-        # http://docs.scipy.org/doc/numpy/reference/ufuncs.html
+-
+-        # some functions are skipped because it may return different result
+-        # for unicode input depending on numpy version
+-
+-        for name, idx in compat.iteritems(self.indices):
+-            for func in [np.exp, np.exp2, np.expm1, np.log, np.log2, np.log10,
+-                         np.log1p, np.sqrt, np.sin, np.cos, np.tan, np.arcsin,
+-                         np.arccos, np.arctan, np.sinh, np.cosh, np.tanh,
+-                         np.arcsinh, np.arccosh, np.arctanh, np.deg2rad,
+-                         np.rad2deg]:
+-                if isinstance(idx, DatetimeIndexOpsMixin):
+-                    # raise TypeError or ValueError (PeriodIndex)
+-                    # PeriodIndex behavior should be changed in future version
+-                    with pytest.raises(Exception):
+-                        with np.errstate(all='ignore'):
+-                            func(idx)
+-                elif isinstance(idx, (Float64Index, Int64Index, UInt64Index)):
+-                    # coerces to float (e.g. np.sin)
+-                    with np.errstate(all='ignore'):
+-                        result = func(idx)
+-                        exp = Index(func(idx.values), name=idx.name)
+-
+-                    tm.assert_index_equal(result, exp)
+-                    assert isinstance(result, pd.Float64Index)
+-                else:
+-                    # raise AttributeError or TypeError
+-                    if len(idx) == 0:
+-                        continue
+-                    else:
+-                        with pytest.raises(Exception):
+-                            with np.errstate(all='ignore'):
+-                                func(idx)
+-
+-            for func in [np.isfinite, np.isinf, np.isnan, np.signbit]:
+-                if isinstance(idx, DatetimeIndexOpsMixin):
+-                    # raise TypeError or ValueError (PeriodIndex)
+-                    with pytest.raises(Exception):
+-                        func(idx)
+-                elif isinstance(idx, (Float64Index, Int64Index, UInt64Index)):
+-                    # Results in bool array
+-                    result = func(idx)
+-                    assert isinstance(result, np.ndarray)
+-                    assert not isinstance(result, Index)
+-                else:
+-                    if len(idx) == 0:
+-                        continue
+-                    else:
+-                        with pytest.raises(Exception):
+-                            func(idx)
+-
+     def test_hasnans_isnans(self):
+         # GH 11343, added tests for hasnans / isnans
+         for name, index in self.indices.items():
+--- /dev/null
++++ b/pandas/tests/indexes/test_numpy_compat.py
+@@ -0,0 +1,82 @@
++import numpy as np
++import pytest
++
++from pandas import (
++    DatetimeIndex, Float64Index, Index, Int64Index, TimedeltaIndex,
++    UInt64Index)
++from pandas.core.indexes.datetimelike import DatetimeIndexOpsMixin
++from pandas.util import testing as tm
++
++
++ at pytest.mark.parametrize(
++    'func', [np.exp, np.exp2, np.expm1, np.log, np.log2, np.log10,
++             np.log1p, np.sqrt, np.sin, np.cos, np.tan, np.arcsin,
++             np.arccos, np.arctan, np.sinh, np.cosh, np.tanh,
++             np.arcsinh, np.arccosh, np.arctanh, np.deg2rad,
++             np.rad2deg],
++    ids=lambda x: x.__name__)
++def test_numpy_ufuncs_basic(indices, func):
++    # test ufuncs of numpy, see:
++    # http://docs.scipy.org/doc/numpy/reference/ufuncs.html
++
++    idx = indices
++    if isinstance(idx, DatetimeIndexOpsMixin):
++        # raise TypeError or ValueError (PeriodIndex)
++        with pytest.raises(Exception):
++            with np.errstate(all='ignore'):
++                func(idx)
++    elif isinstance(idx, (Float64Index, Int64Index, UInt64Index)):
++        # coerces to float (e.g. np.sin)
++        with np.errstate(all='ignore'):
++            result = func(idx)
++            exp = Index(func(idx.values), name=idx.name)
++
++        tm.assert_index_equal(result, exp)
++        assert isinstance(result, Float64Index)
++    else:
++        # raise AttributeError or TypeError
++        if len(idx) == 0:
++            pass
++        else:
++            with pytest.raises(Exception):
++                with np.errstate(all='ignore'):
++                    func(idx)
++
++
++ at pytest.mark.parametrize(
++    'func', [np.isfinite, np.isinf, np.isnan, np.signbit],
++    ids=lambda x: x.__name__)
++def test_numpy_ufuncs_other(indices, func):
++    # test ufuncs of numpy, see:
++    # http://docs.scipy.org/doc/numpy/reference/ufuncs.html
++
++    idx = indices
++    if isinstance(idx, (DatetimeIndex, TimedeltaIndex)):
++
++        # ok under numpy >= 1.17
++        if func in [np.isfinite]:
++            # Results in bool array
++            result = func(idx)
++            assert isinstance(result, np.ndarray)
++            assert not isinstance(result, Index)
++        else:
++            # raise TypeError or ValueError (PeriodIndex)
++            with pytest.raises(Exception):
++                func(idx)
++
++    elif isinstance(idx, DatetimeIndexOpsMixin):
++        # raise TypeError or ValueError (PeriodIndex)
++        with pytest.raises(Exception):
++            func(idx)
++
++    elif isinstance(idx, (Float64Index, Int64Index, UInt64Index)):
++        # Results in bool array
++        result = func(idx)
++        assert isinstance(result, np.ndarray)
++        assert not isinstance(result, Index)
++    else:
++        if len(idx) == 0:
++            pass
++        else:
++            with pytest.raises(Exception):
++                func(idx)
diff -Nru pandas-0.23.3+dfsg/debian/rules pandas-0.23.3+dfsg/debian/rules
--- pandas-0.23.3+dfsg/debian/rules	2019-10-22 16:10:49.000000000 +0000
+++ pandas-0.23.3+dfsg/debian/rules	2019-11-06 00:15:32.000000000 +0000
@@ -104,7 +104,7 @@
 override_dh_auto_test: override_dh_auto_install
 	set -e; \
 	for ver in ${PY3VERS}; do \
-	  if [ $$ver = 3.8 ] || [ $$ver = 3.7 ] ; then \
+	  if [ $$ver = 3.8 ] ; then \
 		debian/rules python-test$$ver || true; \
 	  else \
 		debian/rules python-test$$ver; \


More information about the debian-science-maintainers mailing list