Skip to content

Commit

Permalink
(feat): working with zarr-python
Browse files Browse the repository at this point in the history
  • Loading branch information
ilan-gold committed Jul 19, 2024
1 parent 0db1791 commit 0bd57b6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ docs/_build/

# Pyenv
.python-version

# testing
data/
fixture/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "zarrs_python"]
path = zarrs_python
url = https://github.com/zarr-developers/zarr-python.git
17 changes: 16 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,20 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]
dependencies = [
'asciitree',
'numpy>=1.24',
'fasteners',
'numcodecs[msgpack]>=0.10.0',
'fsspec>2024',
'crc32c',
'zstandard',
'typing_extensions',
'donfig',
'pytest',
'universal_pathlib>=0.2.0'
]

[tool.maturin]
features = ["pyo3/extension-module"]
module-name = "zarrs_python.zarrs_python_internal"
features = ["pyo3/extension-module"]
8 changes: 4 additions & 4 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ use pyo3::prelude::*;
use zarrs::array::{Array as RustArray};
use zarrs::array_subset::ArraySubset;
use zarrs::storage::ReadableStorageTraits;
use pyo3::types::{PyInt, PySlice, PyTuple};
use pyo3::types::{PyInt, PyList, PySlice, PyTuple};
use std::ops::Range;
use dlpark::prelude::*;
use std::ffi::c_void;


#[pyclass]
pub struct Array {
pub struct ZarrsPythonArray {
pub arr: RustArray<dyn ReadableStorageTraits + 'static>
}

impl Array {
impl ZarrsPythonArray {

fn maybe_convert_u64(&self, ind: i32, axis: usize) -> PyResult<u64> {
let mut ind_u64: u64 = ind as u64;
Expand Down Expand Up @@ -43,7 +43,7 @@ impl Array {
}

#[pymethods]
impl Array {
impl ZarrsPythonArray {

pub fn __getitem__(&self, key: &Bound<'_, PyAny>) -> PyResult<ManagerCtx<PyZarrArr>> {
let selection: ArraySubset;
Expand Down
12 changes: 5 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use array::Array;
use pyo3::{exceptions::PyTypeError, prelude::*};
use std::sync::Arc;
use zarrs::storage::{ReadableStorage, store};
Expand All @@ -8,22 +7,21 @@ mod array;
mod utils;

#[pyfunction]
fn open_array(path: &str) -> PyResult<array::Array> {
fn open_array(path: &str) -> PyResult<array::ZarrsPythonArray> {
let s: ReadableStorage;
if path.starts_with("http://") | path.starts_with("https://") {
s = Arc::new(store::HTTPStore::new(path).or_else(|x| utils::err(x.to_string()))?);
} else {
s = Arc::new(store::FilesystemStore::new(path).or_else(|x| utils::err(x.to_string()))?);
}
let arr = RustArray::new(s, &"/").or_else(|x| utils::err(x.to_string()))?;
Ok(array::Array{ arr })
Ok(array::ZarrsPythonArray{ arr })
}

/// A Python module implemented in Rust.
#[pymodule]
fn zarrs_python(m: &Bound<'_, PyModule>) -> PyResult<()> {
let core = PyModule::new_bound(m.py(),"core")?;
core.add_function(wrap_pyfunction!(open_array, &core)?)?;
let _ = m.add_submodule(&core);
fn zarrs_python_internal(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction!(open_array, m)?)?;
m.add_class::<array::ZarrsPythonArray>()?;
Ok(())
}
1 change: 1 addition & 0 deletions zarrs_python
Submodule zarrs_python added at 37a844

0 comments on commit 0bd57b6

Please sign in to comment.