Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy 2.0 compatibility #319

Merged
merged 15 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,17 @@ jobs:
fetch-depth: 0

- name: "Building ${{ matrix.os }} (${{ matrix.arch }}) wheels"
uses: pypa/cibuildwheel@v2.15.0
uses: pypa/cibuildwheel@v2.16.5
env:
# Skips pypy py36,37
CIBW_SKIP: "pp* cp36-* cp37-*
CIBW_SKIP: "pp* cp36-* cp37-*"
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BUILD_FRONTEND: build
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_TEST_SKIP: "*_arm64"
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: >
python -c "import cftime; print(f'cftime v{cftime.__version__}')" &&
python -m pip install -r {package}/requirements-dev.txt &&
python -m pip install check-manifest cython pytest pytest-cov &&
python -m pytest -vv {package}/test

- uses: actions/upload-artifact@v3
Expand Down
19 changes: 18 additions & 1 deletion .github/workflows/tests_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ on:
jobs:
run:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
os: [windows-latest, ubuntu-latest, macos-latest]
platform: [x64, x32]
experimental: [false]
exclude:
- os: macos-latest
platform: x32
include:
- python-version: "3.12"
os: "ubuntu-latest"
experimental: true

steps:
- uses: actions/checkout@v4
Expand All @@ -31,11 +37,22 @@ jobs:
cython>=0.29.20
pytest
pytest-cov
- name: Install unstable dependencies
if: matrix.experimental == true
shell: bash -l {0}
run: |
python -m pip install \
--index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/ \
--trusted-host pypi.anaconda.org \
--no-deps --pre --upgrade \
numpy;
python -m pip install -v -e . --no-deps --no-build-isolation --force-reinstall

- name: Install cftime
if: matrix.experimental != true
shell: bash -l {0}
run: |
pip install -v -e . --no-deps --force-reinstall
python -m pip install -v -e . --no-deps --force-reinstall

- name: Run Tests
shell: bash -l {0}
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/tests_latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ jobs:
run: |
python -m pip install --upgrade pip

- name: Install cftime dependencies via pip
- name: Install unstable cftime dependencies via pip
run: |
python -m pip install -r requirements-dev.txt
python -m pip install --pre -r requirements-dev.txt
# get nightly wheels for numpy
python -m pip install \
--index-url https://pypi.anaconda.org/scientific-python-nightly-wheels/simple/ \
--trusted-host pypi.anaconda.org \
--no-deps --pre --upgrade \
numpy

- name: Install cftime
run: |
Expand Down
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[build-system]
requires = ["setuptools>=41.2", "cython>=0.29.20", "wheel", "oldest-supported-numpy; python_version<'3.12.0.rc1'", "numpy>=1.26.0b1; python_version>='3.12.0.rc1'"]
requires = [
"setuptools>=41.2",
"cython>=0.29.20",
"wheel",
"oldest-supported-numpy ; python_version < '3.9'",
"numpy>=2.0.0rc1,<3 ; python_version >= '3.9'",
]
build-backend = "setuptools.build_meta"
3 changes: 3 additions & 0 deletions src/cftime/_cftime.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ from cpython.object cimport (PyObject_RichCompare, Py_LT, Py_LE, Py_EQ,
from numpy cimport int64_t, int32_t
import cython
import numpy as np
cimport numpy as np
import re
import time
from datetime import datetime as datetime_python
from datetime import timedelta, MINYEAR, MAXYEAR
import warnings
from ._strptime import _strptime

np.import_array()

microsec_units = ['microseconds','microsecond', 'microsec', 'microsecs']
millisec_units = ['milliseconds', 'millisecond', 'millisec', 'millisecs', 'msec', 'msecs', 'ms']
sec_units = ['second', 'seconds', 'sec', 'secs', 's']
Expand Down
Loading