1
0
forked from pool/python-sherpa
python-sherpa/sherpa-numpy-1.20.patch
Dirk Mueller 14bc0b2cc6 Accepting request 873000 from home:badshah400:branches:devel:languages:python:numeric
* Update to version 4.13.0.
* Add sherpa-numpy-1.20.patch: Fix test errors with numpy 1.20 [gh#sherpa/sherpa#/1092]; patch committed upstream.
* Disable python 3.6 flavour: dependency numpy not supported.

OBS-URL: https://build.opensuse.org/request/show/873000
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python:numeric/python-sherpa?expand=0&rev=13
2021-02-17 08:51:12 +00:00

201 lines
7.2 KiB
Diff

From 1ca81268c560b712677f91c98c5481ef473bfa0e Mon Sep 17 00:00:00 2001
From: Douglas Burke <dburke.gw@gmail.com>
Date: Sun, 31 Jan 2021 19:03:24 -0500
Subject: [PATCH 1/3] Whitelist np.bool/int/float warning from NumPy 1.20 in
tests
As well as white-listing the warnings I've had to tweak one set
of tests which was explicitly checking the warning messages
(and so needed to ignore the known warnings).
---
.../astro/tests/test_astro_data_swift_unit.py | 21 ++++++----
sherpa/conftest.py | 38 +++++++++++++++----
2 files changed, 43 insertions(+), 16 deletions(-)
Index: sherpa-4.13.0/sherpa/astro/tests/test_astro_data_swift_unit.py
===================================================================
--- sherpa-4.13.0.orig/sherpa/astro/tests/test_astro_data_swift_unit.py
+++ sherpa-4.13.0/sherpa/astro/tests/test_astro_data_swift_unit.py
@@ -172,7 +172,12 @@ def test_read_pha_fails_rmf(make_data_pa
assert emsg in str(excinfo.value)
-def validate_replacement_warning(ws, rtype, label):
+def validate_replacement_warning(ws, rtype, label, is_known_warning):
+ """Check that there is one expected warning."""
+
+ # Filter out the "allowed" warnings.
+ #
+ ws = [w for w in ws if not is_known_warning(w)]
assert len(ws) == 1
w = ws[0]
@@ -185,7 +190,7 @@ def validate_replacement_warning(ws, rty
@requires_data
@requires_fits
-def test_read_arf(make_data_path):
+def test_read_arf(make_data_path, is_known_warning):
"""Can we read in a Swift ARF."""
infile = make_data_path(ARFFILE)
@@ -194,7 +199,7 @@ def test_read_arf(make_data_path):
warnings.simplefilter("always")
arf = io.read_arf(infile)
- validate_replacement_warning(ws, 'ARF', infile)
+ validate_replacement_warning(ws, 'ARF', infile, is_known_warning)
assert isinstance(arf, DataARF)
@@ -262,7 +267,7 @@ def test_read_arf_fails_rmf(make_data_pa
@requires_data
@requires_fits
-def test_read_rmf(make_data_path):
+def test_read_rmf(make_data_path, is_known_warning):
"""Can we read in a Swift RMF."""
infile = make_data_path(RMFFILE)
@@ -271,7 +276,7 @@ def test_read_rmf(make_data_path):
warnings.simplefilter("always")
rmf = io.read_rmf(infile)
- validate_replacement_warning(ws, 'RMF', infile)
+ validate_replacement_warning(ws, 'RMF', infile, is_known_warning)
assert isinstance(rmf, DataRMF)
@@ -362,7 +367,7 @@ def test_read_rmf_fails_arf(make_data_pa
@requires_data
@requires_fits
-def test_can_use_swift_data(make_data_path):
+def test_can_use_swift_data(make_data_path, is_known_warning):
"""A basic check that we can read in and use the Swift data.
Unlike the previous tests, that directly access the io module,
@@ -383,14 +388,14 @@ def test_can_use_swift_data(make_data_pa
warnings.simplefilter("always")
ui.load_rmf(rmffile)
- validate_replacement_warning(ws, 'RMF', rmffile)
+ validate_replacement_warning(ws, 'RMF', rmffile, is_known_warning)
arffile = make_data_path(ARFFILE)
with warnings.catch_warnings(record=True) as ws:
warnings.simplefilter("always")
ui.load_arf(arffile)
- validate_replacement_warning(ws, 'ARF', arffile)
+ validate_replacement_warning(ws, 'ARF', arffile, is_known_warning)
assert ui.get_analysis() == 'energy'
Index: sherpa-4.13.0/sherpa/conftest.py
===================================================================
--- sherpa-4.13.0.orig/sherpa/conftest.py
+++ sherpa-4.13.0/sherpa/conftest.py
@@ -116,7 +116,12 @@ known_warnings = {
# Matplotlib version 2 warnings (from HTML notebook represention)
#
r'np.asscalar\(a\) is deprecated since NumPy v1.16, use a.item\(\) instead',
- r"Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working"
+ r"Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working",
+
+ # numpy 1.20 bool/float issue
+ r'`np.bool` is a deprecated alias for the builtin `bool`. .*',
+ r'`np.int` is a deprecated alias for the builtin `int`. .*',
+ r'`np.float` is a deprecated alias for the builtin `float`. .*',
],
UserWarning:
[
@@ -140,18 +145,11 @@ known_warnings = {
# See https://github.com/ContinuumIO/anaconda-issues/issues/6678
r"numpy.dtype size changed, may indicate binary " +
r"incompatibility. Expected 96, got 88",
- # I am getting the following from astropy with at least python 2.7 during the conda tests
- r"numpy.ufunc size changed, may indicate binary ",
+ # See https://github.com/numpy/numpy/pull/432
+ r"numpy.ufunc size changed",
+ # numpy 1.20 shows this in some tests
+ r"numpy.ndarray size changed, may indicate binary "
],
- VisibleDeprecationWarning:
- [],
-}
-
-# Since Sherpa now requires Python 3.5 at a minumum, the following
-# are always added, but kept as a separate dict and then merged
-# to make it clearer where they came from.
-#
-python3_warnings = {
ResourceWarning:
[
r"unclosed file .*king_kernel.txt.* closefd=True>",
@@ -166,17 +164,9 @@ python3_warnings = {
r"unclosed file .*/dev/null.* closefd=True>",
r"unclosed file .*table.txt.* closefd=True>",
],
- RuntimeWarning:
- [r"invalid value encountered in sqrt",
- # See https://github.com/ContinuumIO/anaconda-issues/issues/6678
- r"numpy.dtype size changed, may indicate binary " +
- r"incompatibility. Expected 96, got 88",
- # See https://github.com/numpy/numpy/pull/432
- r"numpy.ufunc size changed"
- ],
+ VisibleDeprecationWarning:
+ [],
}
-known_warnings.update(python3_warnings)
-
if have_astropy:
astropy_warnings = {
@@ -230,13 +220,8 @@ def capture_all_warnings(request, recwar
pytestconfig injected service for accessing the configuration data
"""
- def known(warning):
- message = warning.message
- for known_warning in known_warnings[type(message)]:
- pattern = re.compile(known_warning)
- if pattern.match(str(message)):
- return True
- return False
+
+ known = check_known_warning
def fin():
warnings = [w for w in recwarn.list
@@ -263,6 +248,28 @@ def capture_all_warnings(request, recwar
request.addfinalizer(fin)
+def check_known_warning(warning):
+ """Return True if this is an "allowed" warning."""
+
+ message = warning.message
+ for known_warning in known_warnings[type(message)]:
+ pattern = re.compile(known_warning)
+ if pattern.match(str(message)):
+ return True
+
+ return False
+
+
+@pytest.fixture
+def is_known_warning():
+ """Returns a function that returns True if this is an "allowed" warning.
+
+ It is not expected that this will see much use.
+ """
+
+ return check_known_warning
+
+
def pytest_configure(config):
"""
This configuration hook overrides the default mechanism for test data self-discovery, if the --test-data command line