From 43313df86bd896e924fb133fccc8babb3c958ad6 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Thu, 21 Dec 2023 21:52:02 +0100 Subject: [PATCH] MAINT: make the import-time check for old Accelerate more specific This avoids triggering a hard import error on any warning; something that may be due to other reasons than using old Accelerate (e.g., gh-25433 is for a specific combination of Clang, macOS and OpenBLAS). Closes gh-25433 --- numpy/__init__.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/numpy/__init__.py b/numpy/__init__.py index 1eccba32c364..1406d9dd9fe9 100644 --- a/numpy/__init__.py +++ b/numpy/__init__.py @@ -461,20 +461,25 @@ def _mac_os_check(): pass if sys.platform == "darwin": + from . import exceptions with warnings.catch_warnings(record=True) as w: _mac_os_check() # Throw runtime error, if the test failed Check for warning and error_message if len(w) > 0: - error_message = "{}: {}".format(w[-1].category.__name__, str(w[-1].message)) - msg = ( - "Polyfit sanity test emitted a warning, most likely due " - "to using a buggy Accelerate backend." - "\nIf you compiled yourself, more information is available at:" - "\nhttps://numpy.org/devdocs/building/index.html" - "\nOtherwise report this to the vendor " - "that provided NumPy.\n{}\n".format(error_message)) - raise RuntimeError(msg) - del w + for _wn in w: + if _wn.category is exceptions.RankWarning: + # Ignore other warnings, they may not be relevant (see gh-25433). + error_message = f"{_wn.category.__name__}: {str(_wn.message)}" + msg = ( + "Polyfit sanity test emitted a warning, most likely due " + "to using a buggy Accelerate backend." + "\nIf you compiled yourself, more information is available at:" + "\nhttps://numpy.org/devdocs/building/index.html" + "\nOtherwise report this to the vendor " + "that provided NumPy.\n\n{}\n".format(error_message)) + raise RuntimeError(msg) + del _wn + del w del _mac_os_check def hugepage_setup():