From a718ce49226dd6d18cda9b22778246f5a84d3bbe Mon Sep 17 00:00:00 2001 From: Lingqing Gan Date: Mon, 15 Apr 2024 06:10:57 -0700 Subject: [PATCH] test: use np.nan for numpy >= 2.0.0 (#270) * fix: use np.nan for numpy >= 2.0.0 * merge unittest-prerelease.yml into unittest.yml * add unit-prerelease to cover's dependencies * fix coverage file upload --- .github/workflows/unittest-prerelease.yml | 32 ----------------------- .github/workflows/unittest.yml | 28 ++++++++++++++++++++ owlbot.py | 2 +- tests/unit/test_dtypes.py | 9 ++++++- 4 files changed, 37 insertions(+), 34 deletions(-) delete mode 100644 .github/workflows/unittest-prerelease.yml diff --git a/.github/workflows/unittest-prerelease.yml b/.github/workflows/unittest-prerelease.yml deleted file mode 100644 index 9d30c75..0000000 --- a/.github/workflows/unittest-prerelease.yml +++ /dev/null @@ -1,32 +0,0 @@ -on: - pull_request: - branches: - - main -name: unittest-prerelease -jobs: - unit-prerelease: - runs-on: ubuntu-latest - strategy: - matrix: - python: ['3.12'] - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python }} - - name: Install nox - run: | - python -m pip install --upgrade setuptools pip wheel - python -m pip install nox - - name: Run unit tests - env: - COVERAGE_FILE: .coverage-prerelease-${{ matrix.python }} - run: | - nox -s unit_prerelease - - name: Upload coverage results - uses: actions/upload-artifact@v4 - with: - name: coverage-artifacts - path: .coverage-${{ matrix.python }} diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index f4a337c..89f021e 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -31,10 +31,38 @@ jobs: name: coverage-artifact-${{ matrix.python }} path: .coverage-${{ matrix.python }} + unit-prerelease: + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.12'] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit tests + env: + COVERAGE_FILE: .coverage-prerelease-${{ matrix.python }} + run: | + nox -s unit_prerelease + - name: Upload coverage results + uses: actions/upload-artifact@v4 + with: + name: coverage-artifact-prerelease-${{ matrix.python }} + path: .coverage-prerelease-${{ matrix.python }} + cover: runs-on: ubuntu-latest needs: - unit + - unit-prerelease steps: - name: Checkout uses: actions/checkout@v4 diff --git a/owlbot.py b/owlbot.py index d1b3c08..2c0ea58 100644 --- a/owlbot.py +++ b/owlbot.py @@ -34,7 +34,7 @@ "pandas": "https://pandas.pydata.org/pandas-docs/stable/" }, ) -s.move(templated_files, excludes=["docs/multiprocessing.rst", "README.rst"]) +s.move(templated_files, excludes=["docs/multiprocessing.rst", "README.rst", ".github/workflows/unittest.yml"]) # ---------------------------------------------------------------------------- # Fixup files diff --git a/tests/unit/test_dtypes.py b/tests/unit/test_dtypes.py index 6584cee..f2c5593 100644 --- a/tests/unit/test_dtypes.py +++ b/tests/unit/test_dtypes.py @@ -314,7 +314,7 @@ def test__validate_scalar_invalid(dtype): (False, None), (True, None), (True, pd.NaT if pd else None), - (True, np.NaN if pd else None), + (True, "np.nan" if pd else None), (True, 42), ], ) @@ -328,6 +328,13 @@ def test_take(dtype, allow_fill, fill_value): if dtype == "dbdate" else datetime.time(0, 42, 42, 424242) ) + elif fill_value == "np.nan": + expected_fill = pd.NaT + try: + fill_value = np.NaN + except AttributeError: + # `np.NaN` was removed in NumPy 2.0 release. Use `np.nan` instead + fill_value = np.nan else: expected_fill = pd.NaT b = a.take([1, -1, 3], allow_fill=True, fill_value=fill_value)