diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 04bbf98..d1b9464 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,8 +15,6 @@ jobs: runs-on: "ubuntu-22.04" steps: - uses: actions/checkout@v4 - - name: Install dev-requirements - run: pip install -r dev-requirements.txt - uses: actions/cache@v4 with: path: | @@ -24,12 +22,17 @@ jobs: ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Test - run: cargo test --release - - name: Test no numpy installed works + - name: Test no numpy run: | - pip uninstall numpy -y cargo test --release --features nonumpy + - name: Install numpy v1 + run: pip install 'numpy>=1,<2' 'pandas>=1,<2' + - name: Test numpy v1 + run: cargo test --release + - name: Install numpy v2 + run: pip install 'numpy>=2,<3' 'pandas>=2,<3' + - name: Test numpy v2 + run: cargo test --release build: if: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }} diff --git a/dev-requirements.txt b/dev-requirements.txt index 1417be9..f4ce98a 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,4 +1,4 @@ -maturin==0.14.* +maturin==1.4.* numpy==1.* pandas==1.* numpy-financial==1.* diff --git a/src/conversions.rs b/src/conversions.rs index cc0eb48..ffca1c0 100644 --- a/src/conversions.rs +++ b/src/conversions.rs @@ -1,9 +1,6 @@ use std::str::FromStr; -use numpy::{ - datetime::{units, Datetime as datetime64}, - PyArray1, -}; +use numpy::PyArray1; use pyo3::{ exceptions::{PyTypeError, PyValueError}, prelude::*, @@ -101,15 +98,6 @@ impl From<&PyDate> for DateLike { } } -impl From<&datetime64> for DateLike { - fn from(value: &datetime64) -> Self { - let days_since_unix_epoch: i32 = Into::::into(*value) as i32; - let date = Date::from_julian_day(UNIX_EPOCH_JULIAN_DAY + days_since_unix_epoch).unwrap(); - - date.into() - } -} - impl<'s> FromPyObject<'s> for DateLike { fn extract(obj: &'s PyAny) -> PyResult { if let Ok(py_date) = obj.downcast::() { @@ -126,7 +114,7 @@ impl<'s> FromPyObject<'s> for DateLike { match obj.get_type().name()? { "datetime64" => Ok(obj .call_method1("astype", ("datetime64[D]",))? - .call_method1("astype", ("int",))? + .call_method1("astype", ("int32",))? .extract::()? .into()), @@ -150,11 +138,12 @@ where fn extract_date_series_from_numpy(series: &PyAny) -> PyResult> { Ok(series .call_method1("astype", ("datetime64[D]",))? - .downcast::>>()? + .call_method1("astype", ("int32",))? + .downcast::>()? .readonly() .as_slice()? .iter() - .map(|x| x.into()) + .map(|&x| DateLike::from(DaysSinceUnixEpoch(x))) .collect()) }