From ec3bd5cf2e72e8e361a6e1cd2c336a3e2ab2a480 Mon Sep 17 00:00:00 2001 From: Jake VanderPlas Date: Tue, 19 Dec 2023 16:04:34 -0800 Subject: [PATCH] CI: add a build against numpy nightly --- .github/workflows/nightly-test.yml | 53 ++++++++++++++++++++++++++++ ml_dtypes/tests/custom_float_test.py | 10 +++++- pytest.ini | 1 + 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/nightly-test.yml diff --git a/.github/workflows/nightly-test.yml b/.github/workflows/nightly-test.yml new file mode 100644 index 00000000..aeba8e3c --- /dev/null +++ b/.github/workflows/nightly-test.yml @@ -0,0 +1,53 @@ +name: Test + +on: + # Trigger the workflow on push or pull request, but only on main branch + push: + branches: + - main + pull_request: + branches: + - main + +permissions: + contents: read # to fetch code + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: 3.9 + - uses: pre-commit/action@v3.0.0 + build: + name: ${{ matrix.os }} Python ${{ matrix.python-version }} with nightly numpy + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: ["ubuntu-latest"] + python-version: ["3.12"] + + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install setuptools wheel + python -m pip install -U --pre numpy \ + -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple + python -c "import numpy; print(f'{numpy.__version__=}')" + - name: Build ml_dtypes + run: | + python -m pip install .[dev] --no-build-isolation + - name: Run tests + run: | + pytest -n auto diff --git a/ml_dtypes/tests/custom_float_test.py b/ml_dtypes/tests/custom_float_test.py index d71ae8b1..6ca15b21 100644 --- a/ml_dtypes/tests/custom_float_test.py +++ b/ml_dtypes/tests/custom_float_test.py @@ -37,6 +37,14 @@ float8_e5m2fnuz = ml_dtypes.float8_e5m2fnuz +try: + # numpy >= 2.0 + ComplexWarning = np.exceptions.ComplexWarning +except AttributeError: + # numpy < 2.0 + ComplexWarning = np.ComplexWarning + + @contextlib.contextmanager def ignore_warning(**kw): with warnings.catch_warnings(): @@ -703,7 +711,7 @@ def testCasts(self, float_type): self.assertTrue(np.all(x == z)) self.assertEqual(dtype, z.dtype) - @ignore_warning(category=np.ComplexWarning) + @ignore_warning(category=ComplexWarning) def testConformNumpyComplex(self, float_type): for dtype in [np.complex64, np.complex128, np.clongdouble]: x = np.array([1.5, 2.5 + 2.0j, 3.5], dtype=dtype) diff --git a/pytest.ini b/pytest.ini index 9e90ef7c..2842b4cf 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,4 @@ [pytest] filterwarnings = error + ignore:numpy.core._multiarray_umat.*:DeprecationWarning