diff --git a/pyo3-arrow/src/array.rs b/pyo3-arrow/src/array.rs index 42d385b..b0fc7e2 100644 --- a/pyo3-arrow/src/array.rs +++ b/pyo3-arrow/src/array.rs @@ -40,7 +40,7 @@ use crate::{PyDataType, PyField}; /// In particular, storing a [FieldRef] is required to persist Arrow extension metadata through the /// C Data Interface. #[derive(Debug)] -#[pyclass(module = "arro3.core._core", name = "Array", subclass)] +#[pyclass(module = "arro3.core._core", name = "Array", subclass, frozen)] pub struct PyArray { array: ArrayRef, field: FieldRef, diff --git a/pyo3-arrow/src/array_reader.rs b/pyo3-arrow/src/array_reader.rs index f4f71e8..984d995 100644 --- a/pyo3-arrow/src/array_reader.rs +++ b/pyo3-arrow/src/array_reader.rs @@ -20,7 +20,7 @@ use crate::{PyArray, PyChunkedArray, PyField}; /// A Python-facing Arrow array reader. /// /// This is a wrapper around a [ArrayReader]. -#[pyclass(module = "arro3.core._core", name = "ArrayReader", subclass)] +#[pyclass(module = "arro3.core._core", name = "ArrayReader", subclass, frozen)] pub struct PyArrayReader(pub(crate) Mutex>>); impl PyArrayReader { @@ -79,7 +79,7 @@ impl PyArrayReader { /// Export this to a Python `arro3.core.ArrayReader`. #[allow(clippy::wrong_self_convention)] - pub fn to_arro3<'py>(&'py mut self, py: Python<'py>) -> PyResult> { + pub fn to_arro3<'py>(&'py self, py: Python<'py>) -> PyResult> { let arro3_mod = py.import(intern!(py, "arro3.core"))?; arro3_mod.getattr(intern!(py, "ArrayReader"))?.call_method1( intern!(py, "from_arrow_pycapsule"), @@ -89,7 +89,7 @@ impl PyArrayReader { /// Export this to a Python `nanoarrow.ArrayStream`. #[allow(clippy::wrong_self_convention)] - pub fn to_nanoarrow<'py>(&'py mut self, py: Python<'py>) -> PyResult> { + pub fn to_nanoarrow<'py>(&'py self, py: Python<'py>) -> PyResult> { to_nanoarrow_array_stream(py, &self.__arrow_c_stream__(py, None)?) } } @@ -120,7 +120,7 @@ impl PyArrayReader { #[pyo3(signature = (requested_schema=None))] fn __arrow_c_stream__<'py>( - &'py mut self, + &'py self, py: Python<'py>, requested_schema: Option>, ) -> PyArrowResult> { @@ -135,11 +135,11 @@ impl PyArrayReader { // Return self // https://stackoverflow.com/a/52056290 - fn __iter__<'py>(&'py mut self, py: Python<'py>) -> PyResult> { + fn __iter__<'py>(&'py self, py: Python<'py>) -> PyResult> { self.to_arro3(py) } - fn __next__(&mut self) -> PyArrowResult { + fn __next__(&self) -> PyArrowResult { self.read_next_array() } @@ -189,7 +189,7 @@ impl PyArrayReader { Ok(PyField::new(self.field_ref()?).into()) } - fn read_all(&mut self) -> PyArrowResult { + fn read_all(&self) -> PyArrowResult { let stream = self .0 .lock() @@ -204,7 +204,7 @@ impl PyArrayReader { Ok(PyChunkedArray::try_new(arrays, field)?.into()) } - fn read_next_array(&mut self) -> PyArrowResult { + fn read_next_array(&self) -> PyArrowResult { let mut inner = self.0.lock().unwrap(); let stream = inner .as_mut() diff --git a/pyo3-arrow/src/buffer.rs b/pyo3-arrow/src/buffer.rs index 7e6a4f4..7069610 100644 --- a/pyo3-arrow/src/buffer.rs +++ b/pyo3-arrow/src/buffer.rs @@ -41,7 +41,7 @@ use crate::PyArray; /// The Python buffer protocol is implemented on this buffer to enable zero-copy data transfer of /// the core buffer into Python. This allows for zero-copy data sharing with numpy via /// `numpy.frombuffer`. -#[pyclass(module = "arro3.core._core", name = "Buffer", subclass)] +#[pyclass(module = "arro3.core._core", name = "Buffer", subclass, frozen)] pub struct PyArrowBuffer(Buffer); impl AsRef for PyArrowBuffer { @@ -87,7 +87,7 @@ impl PyArrowBuffer { /// This is taken from opendal: /// https://github.com/apache/opendal/blob/d001321b0f9834bc1e2e7d463bcfdc3683e968c9/bindings/python/src/utils.rs#L51-L72 unsafe fn __getbuffer__( - slf: PyRefMut, + slf: PyRef, view: *mut ffi::Py_buffer, flags: c_int, ) -> PyResult<()> { diff --git a/pyo3-arrow/src/chunked.rs b/pyo3-arrow/src/chunked.rs index 23e6a18..e501e43 100644 --- a/pyo3-arrow/src/chunked.rs +++ b/pyo3-arrow/src/chunked.rs @@ -25,7 +25,7 @@ use crate::{PyArray, PyDataType, PyField, PyScalar}; /// /// This is a wrapper around a [FieldRef] and a `Vec` of [ArrayRef]. #[derive(Debug)] -#[pyclass(module = "arro3.core._core", name = "ChunkedArray", subclass)] +#[pyclass(module = "arro3.core._core", name = "ChunkedArray", subclass, frozen)] pub struct PyChunkedArray { chunks: Vec, field: FieldRef, diff --git a/pyo3-arrow/src/datatypes.rs b/pyo3-arrow/src/datatypes.rs index f8ade06..84e1ee6 100644 --- a/pyo3-arrow/src/datatypes.rs +++ b/pyo3-arrow/src/datatypes.rs @@ -32,7 +32,7 @@ impl<'a> FromPyObject<'a> for PyTimeUnit { /// A Python-facing wrapper around [DataType]. #[derive(PartialEq, Eq, Debug)] -#[pyclass(module = "arro3.core._core", name = "DataType", subclass)] +#[pyclass(module = "arro3.core._core", name = "DataType", subclass, frozen)] pub struct PyDataType(DataType); impl PyDataType { diff --git a/pyo3-arrow/src/field.rs b/pyo3-arrow/src/field.rs index f0e31ef..22a16e0 100644 --- a/pyo3-arrow/src/field.rs +++ b/pyo3-arrow/src/field.rs @@ -20,7 +20,7 @@ use crate::PyDataType; /// /// This is a wrapper around a [FieldRef]. #[derive(Debug)] -#[pyclass(module = "arro3.core._core", name = "Field", subclass)] +#[pyclass(module = "arro3.core._core", name = "Field", subclass, frozen)] pub struct PyField(FieldRef); impl PyField { diff --git a/pyo3-arrow/src/record_batch.rs b/pyo3-arrow/src/record_batch.rs index d0f19d8..590f0ab 100644 --- a/pyo3-arrow/src/record_batch.rs +++ b/pyo3-arrow/src/record_batch.rs @@ -24,7 +24,7 @@ use crate::{PyArray, PyField, PySchema}; /// A Python-facing Arrow record batch. /// /// This is a wrapper around a [RecordBatch]. -#[pyclass(module = "arro3.core._core", name = "RecordBatch", subclass)] +#[pyclass(module = "arro3.core._core", name = "RecordBatch", subclass, frozen)] #[derive(Debug)] pub struct PyRecordBatch(RecordBatch); diff --git a/pyo3-arrow/src/record_batch_reader.rs b/pyo3-arrow/src/record_batch_reader.rs index 1963889..66e799b 100644 --- a/pyo3-arrow/src/record_batch_reader.rs +++ b/pyo3-arrow/src/record_batch_reader.rs @@ -22,7 +22,12 @@ use crate::{PyRecordBatch, PySchema, PyTable}; /// A Python-facing Arrow record batch reader. /// /// This is a wrapper around a [RecordBatchReader]. -#[pyclass(module = "arro3.core._core", name = "RecordBatchReader", subclass)] +#[pyclass( + module = "arro3.core._core", + name = "RecordBatchReader", + subclass, + frozen +)] pub struct PyRecordBatchReader(pub(crate) Mutex>>); impl PyRecordBatchReader { @@ -81,7 +86,7 @@ impl PyRecordBatchReader { } /// Export this to a Python `arro3.core.RecordBatchReader`. - pub fn to_arro3<'py>(&'py mut self, py: Python<'py>) -> PyResult> { + pub fn to_arro3<'py>(&'py self, py: Python<'py>) -> PyResult> { let arro3_mod = py.import(intern!(py, "arro3.core"))?; arro3_mod .getattr(intern!(py, "RecordBatchReader"))? @@ -92,7 +97,7 @@ impl PyRecordBatchReader { } /// Export this to a Python `nanoarrow.ArrayStream`. - pub fn to_nanoarrow<'py>(&'py mut self, py: Python<'py>) -> PyResult> { + pub fn to_nanoarrow<'py>(&'py self, py: Python<'py>) -> PyResult> { to_nanoarrow_array_stream(py, &self.__arrow_c_stream__(py, None)?) } @@ -155,7 +160,7 @@ impl PyRecordBatchReader { #[pyo3(signature = (requested_schema=None))] fn __arrow_c_stream__<'py>( - &'py mut self, + &'py self, py: Python<'py>, requested_schema: Option>, ) -> PyArrowResult> { @@ -170,11 +175,11 @@ impl PyRecordBatchReader { // Return self // https://stackoverflow.com/a/52056290 - fn __iter__<'py>(&'py mut self, py: Python<'py>) -> PyResult> { + fn __iter__<'py>(&'py self, py: Python<'py>) -> PyResult> { self.to_arro3(py) } - fn __next__(&mut self) -> PyArrowResult { + fn __next__(&self) -> PyArrowResult { self.read_next_batch() } @@ -216,7 +221,7 @@ impl PyRecordBatchReader { self.0.lock().unwrap().is_none() } - fn read_all(&mut self) -> PyArrowResult { + fn read_all(&self) -> PyArrowResult { let stream = self .0 .lock() @@ -231,7 +236,7 @@ impl PyRecordBatchReader { Ok(PyTable::try_new(batches, schema)?.into()) } - fn read_next_batch(&mut self) -> PyArrowResult { + fn read_next_batch(&self) -> PyArrowResult { let mut inner = self.0.lock().unwrap(); let stream = inner .as_mut() diff --git a/pyo3-arrow/src/scalar.rs b/pyo3-arrow/src/scalar.rs index c81b4cb..b0220e0 100644 --- a/pyo3-arrow/src/scalar.rs +++ b/pyo3-arrow/src/scalar.rs @@ -19,7 +19,7 @@ use crate::{PyArray, PyField}; /// A Python-facing Arrow scalar #[derive(Debug)] -#[pyclass(module = "arro3.core._core", name = "Scalar", subclass)] +#[pyclass(module = "arro3.core._core", name = "Scalar", subclass, frozen)] pub struct PyScalar { array: ArrayRef, field: FieldRef, diff --git a/pyo3-arrow/src/schema.rs b/pyo3-arrow/src/schema.rs index 96331a6..1552f56 100644 --- a/pyo3-arrow/src/schema.rs +++ b/pyo3-arrow/src/schema.rs @@ -20,7 +20,7 @@ use crate::{PyDataType, PyField, PyTable}; /// /// This is a wrapper around a [SchemaRef]. #[derive(Debug)] -#[pyclass(module = "arro3.core._core", name = "Schema", subclass)] +#[pyclass(module = "arro3.core._core", name = "Schema", subclass, frozen)] pub struct PySchema(SchemaRef); impl PySchema { diff --git a/pyo3-arrow/src/table.rs b/pyo3-arrow/src/table.rs index fbabf7e..5786a8d 100644 --- a/pyo3-arrow/src/table.rs +++ b/pyo3-arrow/src/table.rs @@ -32,7 +32,7 @@ use crate::{PyChunkedArray, PyField, PyRecordBatch, PyRecordBatchReader, PySchem /// A Python-facing Arrow table. /// /// This is a wrapper around a [SchemaRef] and a `Vec` of [RecordBatch]. -#[pyclass(module = "arro3.core._core", name = "Table", subclass)] +#[pyclass(module = "arro3.core._core", name = "Table", subclass, frozen)] #[derive(Debug)] pub struct PyTable { batches: Vec,