Skip to content

Commit f979580

Browse files
committed
fix numpy mkl test
1 parent ac28d14 commit f979580

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Dockerfile.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ RUN uv pip uninstall --system google-cloud-bigquery-storage
3232
# to avoid affecting the larger build, we'll post-install it.
3333
RUN uv pip install --no-build-isolation --system "git+https://github.com/Kaggle/learntools"
3434

35+
# DO_NOT_MERGE: Wait for Colab to fix mkl in image.
36+
RUN uv pip install --system --force-reinstall -i https://pypi.anaconda.org/intel/simple numpy
37+
3538
# b/328788268 We install an incompatible pair of libs (shapely<2, libpysal==4.9.2) so we can't put this one in the requirements.txt
3639
RUN uv pip install --system "libpysal==4.9.2"
3740

tests/test_numpy.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
from distutils.version import StrictVersion
44

55
import numpy as np
6-
from numpy.distutils.system_info import get_info
6+
import io
7+
from contextlib import redirect_stdout
78

8-
class TestNumpy(unittest.TestCase):
9+
class TestNumpy(unittest.TestCase):
910
def test_version(self):
1011
# b/370860329: newer versions are not capable with current tensorflow
1112
self.assertEqual(StrictVersion(np.__version__), StrictVersion("1.26.4"))
@@ -18,5 +19,13 @@ def test_array(self):
1819
# Numpy must be linked to the MKL. (Occasionally, a third-party package will muck up the installation
1920
# and numpy will be reinstalled with an OpenBLAS backing.)
2021
def test_mkl(self):
21-
# This will throw an exception if the MKL is not linked correctly or return an empty dict.
22-
self.assertTrue(get_info("blas_mkl"))
22+
try:
23+
from numpy.distutils.system_info import get_info
24+
# This will throw an exception if the MKL is not linked correctly or return an empty dict.
25+
self.assertTrue(get_info("blas_mkl"))
26+
except:
27+
# Fallback to check if mkl is present via show_config()
28+
config_out = io.StringIO()
29+
with redirect_stdout(config_out):
30+
np.show_config()
31+
self.assertIn("mkl_rt", config_out.getvalue())

0 commit comments

Comments
 (0)