Skip to content

Commit

Permalink
bump polars version
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhang committed Feb 28, 2024
1 parent 75e4101 commit 9aab385
Show file tree
Hide file tree
Showing 24 changed files with 336 additions and 705 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ jobs:
- name: Install dependency
run: |
sudo pip install --upgrade pip
pip install --user pytest hypothesis \
Pygments==2.6.1 sphinx==4.4.0 pandoc nbsphinx \
pip install --user Pygments==2.6.1 sphinx==4.4.0 pandoc nbsphinx \
sphinx-autodoc-typehints sphinx_rtd_theme \
markupsafe==2.0.1
- name: Build and test package
run: |
cd ${GITHUB_WORKSPACE}/anndata-hdf5 && cargo test --all --no-fail-fast
cd ${GITHUB_WORKSPACE}/anndata && cargo test --all --no-fail-fast
cd ${GITHUB_WORKSPACE}/python && \
pip install --user .
cd ${GITHUB_WORKSPACE}/python && pip install --user .[test]
pytest ${GITHUB_WORKSPACE}/python/tests
- name: Build doc
Expand Down
7 changes: 4 additions & 3 deletions anndata-hdf5/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "anndata-hdf5"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
rust-version = "1.65"
authors = ["Kai Zhang <kai@kzhang.org>"]
Expand All @@ -11,7 +11,7 @@ repository = "https://github.com/kaizhang/anndata-rs"
homepage = "https://github.com/kaizhang/anndata-rs"

[dependencies]
anndata = "0.2"
anndata = "0.3"
anyhow = "1.0"
hdf5 = { version = "0.8" }
hdf5-sys = { version = "0.8", features = ["static", "zlib", "threadsafe"] }
Expand All @@ -20,7 +20,8 @@ libz-sys = { version = "1", features = ["libc"], default-features = false }
ndarray = { version = "0.15" }

[dev-dependencies]
anndata-test-utils = { path = '../anndata-test-utils' }
tempfile = "3.2"
proptest = "1"
rand = "0.8.5"
ndarray-rand = "0.14"
ndarray-rand = "0.14"
58 changes: 58 additions & 0 deletions anndata-hdf5/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use anndata_test_utils::*;
use anndata_hdf5::H5;
use anndata::AnnData;

#[test]
fn test_basic_h5() {
test_basic::<H5>()
}

#[test]
fn test_save_h5() {
test_save::<H5>()
}

#[test]
fn test_speacial_cases_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_speacial_cases(|| adata_gen());
})
}

#[test]
fn test_noncanonical_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_noncanonical(|| adata_gen());
})
}

#[test]
fn test_io_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_io(|| adata_gen());
})
}

#[test]
fn test_index_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_index(|| adata_gen());
})
}

#[test]
fn test_iterator_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_iterator(|| adata_gen());
})
}
18 changes: 18 additions & 0 deletions anndata-test-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "anndata-test-utils"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0"
ndarray = { version = "0.15" }
anndata = ">= 0.2, < 0.4"
num = "0.4"
tempfile = "3.2"
criterion = { version = "0.4", features = ["rayon", "plotters", "cargo_bench_support", "html_reports"] }
proptest = "1"
rand = "0.8.5"
ndarray-rand = "0.14"
nalgebra = { version = "0.32", features = ["rand"] }
nalgebra-sparse = "0.9"
itertools = "0.12"
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ pub fn with_tmp_dir<T, F: FnMut(PathBuf) -> T>(mut func: F) -> T {
func(path)
}

pub fn with_tmp_path<T, F: FnMut(PathBuf) -> T>(mut func: F) -> T {
with_tmp_dir(|dir| func(dir.join("temp.h5")))
}

pub fn empty_adata<B>() -> AnnData<B>
where
B: Backend,
{
let file = tempfile::NamedTempFile::new().unwrap();
AnnData::new(file.path()).unwrap()
}

////////////////////////////////////////////////////////////////////////////////
/// Strategies
////////////////////////////////////////////////////////////////////////////////
Expand Down
113 changes: 50 additions & 63 deletions anndata/tests/anndata_op.rs → anndata-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
#![allow(dead_code, unused)]

mod common;
use common::*;
pub use common::*;

use anndata::{*, data::CsrNonCanonical};
use ndarray::Array2;
use nalgebra_sparse::{CooMatrix, CsrMatrix};
use proptest::prelude::*;
use anndata::{*, data::{DynCscMatrix, CsrNonCanonical}};
use anndata_hdf5::H5;
use std::path::Path;
use nalgebra_sparse::{CooMatrix, CscMatrix, CsrMatrix};

pub fn test_basic<B: Backend>() {
with_tmp_dir(|dir| {
let ann1 = AnnData::<B>::new(dir.join("test1.h5ad")).unwrap();
let ann2 = AnnData::<B>::new(dir.join("test2.h5ad")).unwrap();
AnnDataSet::<B>::new(
[("ann1", ann1), ("ann2", ann2)],
dir.join("dataset.h5ads"),
"sample",
).unwrap();
})
}

pub fn test_save<B: Backend>() {
with_tmp_dir(|dir| {
let input = dir.join("input.h5ad");
let output = dir.join("output.h5ad");
let anndatas = ((0 as usize ..100), (0 as usize ..100))
.prop_flat_map(|(n_obs, n_vars)|
( anndata_strat::<B, _>(&input, n_obs, n_vars),
select_strat(n_obs),
select_strat(n_vars),
)
);
proptest!(ProptestConfig::with_cases(100), |((adata, slice_obs, slice_var) in anndatas)| {
adata.write::<B, _>(&output).unwrap();
let adata_in = AnnData::<B>::open(B::open(&output).unwrap()).unwrap();
prop_assert!(anndata_eq(&adata, &adata_in).unwrap());
adata_in.close().unwrap();

let index = adata.obs_names().select(&slice_obs);
assert_eq!(index.len(), index.into_vec().len());

let select = [slice_obs, slice_var];
adata.write_select::<B, _, _>(&select, &output).unwrap();
adata.subset(&select).unwrap();
let adata_in = AnnData::<B>::open(B::open(&output).unwrap()).unwrap();
prop_assert!(anndata_eq(&adata, &adata_in).unwrap());
adata_in.close().unwrap();
});
});
}

fn test_speacial_cases<F, T>(adata_gen: F)
pub fn test_speacial_cases<F, T>(adata_gen: F)
where
F: Fn() -> T,
T: AnnDataOp,
Expand All @@ -29,7 +66,7 @@ where
adata.x().get::<Array2<f64>>().unwrap().unwrap();
}

fn test_noncanonical<F, T>(adata_gen: F)
pub fn test_noncanonical<F, T>(adata_gen: F)
where
F: Fn() -> T,
T: AnnDataOp,
Expand All @@ -42,12 +79,12 @@ where
vec![1,2,3,4,5,6,7],
).unwrap();
adata.set_x(&CsrNonCanonical::from(&coo)).unwrap();
adata.x().get::<CsrMatrix<i32>>().is_err();
assert!(adata.x().get::<CsrMatrix<i32>>().is_err());
adata.x().get::<CsrNonCanonical<i32>>().unwrap().unwrap();
adata.x().get::<ArrayData>().unwrap().unwrap();
}

fn test_io<F, T>(adata_gen: F)
pub fn test_io<F, T>(adata_gen: F)
where
F: Fn() -> T,
T: AnnDataOp,
Expand All @@ -60,7 +97,7 @@ where
});
}

fn test_index<F, T>(adata_gen: F)
pub fn test_index<F, T>(adata_gen: F)
where
F: Fn() -> T,
T: AnnDataOp,
Expand All @@ -83,7 +120,7 @@ where
});
}

fn test_iterator<F, T>(adata_gen: F)
pub fn test_iterator<F, T>(adata_gen: F)
where
F: Fn() -> T,
T: AnnDataOp,
Expand All @@ -101,54 +138,4 @@ where
prop_assert_eq!(adata.obsm().get_item::<ArrayData>("test2").unwrap().unwrap(), x);
}
});
}


////////////////////////////////////////////////////////////////////////////////
/// Test HDF5 backend
////////////////////////////////////////////////////////////////////////////////

#[test]
fn test_speacial_cases_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_speacial_cases(|| adata_gen());
})
}

#[test]
fn test_noncanonical_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_noncanonical(|| adata_gen());
})
}

#[test]
fn test_io_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_io(|| adata_gen());
})
}

#[test]
fn test_index_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_index(|| adata_gen());
})
}

#[test]
fn test_iterator_h5() {
with_tmp_dir(|dir| {
let file = dir.join("test.h5");
let adata_gen = || AnnData::<H5>::new(&file).unwrap();
test_iterator(|| adata_gen());
})
}
15 changes: 4 additions & 11 deletions anndata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "anndata"
version = "0.2.2"
version = "0.3.1"
edition = "2021"
rust-version = "1.70"
authors = ["Kai Zhang <kai@kzhang.org>"]
Expand All @@ -15,27 +15,20 @@ anyhow = "1.0"
flate2 = "1.0"
log = "0.4"
indexmap = { version = "2.0", features = ["rayon"] }
itertools = "0.11"
itertools = "0.12"
ndarray = { version = "0.15" }
nalgebra-sparse = "0.9"
num = "0.4"
polars = { version = "0.35", features = ["lazy", "decompress-fast", "ndarray", "dtype-full"] }
polars = { version = "0.37", features = ["lazy", "decompress-fast", "ndarray", "dtype-full"] }
parking_lot = "0.12"
replace_with = "0.1"
smallvec = "1.11"
rayon = "1.8"
permutation = "0.4"

[dev-dependencies]
anndata-n5 = { path = '../anndata-n5' }
anndata-hdf5 = { path = '../anndata-hdf5' }
tempfile = "3.2"
criterion = { version = "0.4", features = ["rayon", "plotters", "cargo_bench_support", "html_reports"] }
proptest = "1"
rand = "0.8.5"
ndarray-rand = "0.14"
nalgebra = { version = "0.32", features = ["rand"] }

[[bench]]
name = "main"
harness = false
nalgebra = { version = "0.32", features = ["rand"] }
Loading

0 comments on commit 9aab385

Please sign in to comment.