Skip to content

Commit

Permalink
Allow more str | field
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Jul 28, 2024
1 parent 6cfbb80 commit e4f2b3a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions arro3-core/python/arro3/core/_rust.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ class RecordBatch:
def from_arrow_pycapsule(cls, schema_capsule, array_capsule) -> RecordBatch:
"""Construct this object from bare Arrow PyCapsules"""
def add_column(
self, i: int, field: ArrowSchemaExportable, column: ArrowArrayExportable
self, i: int, field: str | ArrowSchemaExportable, column: ArrowArrayExportable
) -> RecordBatch: ...
def append_column(
self, field: ArrowSchemaExportable, column: ArrowArrayExportable
self, field: str | ArrowSchemaExportable, column: ArrowArrayExportable
) -> RecordBatch:
"""Append column at end of columns.
Expand Down Expand Up @@ -286,7 +286,7 @@ class RecordBatch:
"""Access the schema of this RecordBatch"""
def select(self, columns: list[int] | list[str]) -> RecordBatch: ...
def set_column(
self, i: int, field: ArrowSchemaExportable, column: ArrowArrayExportable
self, i: int, field: str | ArrowSchemaExportable, column: ArrowArrayExportable
) -> RecordBatch: ...
@property
def shape(self) -> tuple[int, int]: ...
Expand Down
14 changes: 7 additions & 7 deletions pyo3-arrow/src/record_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::error::PyArrowResult;
use crate::ffi::from_python::utils::import_array_pycapsules;
use crate::ffi::to_python::nanoarrow::to_nanoarrow_array;
use crate::ffi::to_python::to_array_pycapsules;
use crate::input::{FieldIndexInput, MetadataInput, SelectIndices};
use crate::input::{FieldIndexInput, MetadataInput, NameOrField, SelectIndices};
use crate::schema::display_schema;
use crate::{PyArray, PyField, PySchema};

Expand Down Expand Up @@ -258,11 +258,11 @@ impl PyRecordBatch {
&self,
py: Python,
i: usize,
field: PyField,
field: NameOrField,
column: PyArray,
) -> PyArrowResult<PyObject> {
let mut fields = self.0.schema_ref().fields().to_vec();
fields.insert(i, field.into_inner());
fields.insert(i, field.into_field(column.field()));
let schema = Schema::new_with_metadata(fields, self.0.schema_ref().metadata().clone());

let mut arrays = self.0.columns().to_vec();
Expand All @@ -275,11 +275,11 @@ impl PyRecordBatch {
pub fn append_column(
&self,
py: Python,
field: PyField,
field: NameOrField,
column: PyArray,
) -> PyArrowResult<PyObject> {
let mut fields = self.0.schema_ref().fields().to_vec();
fields.push(field.into_inner());
fields.push(field.into_field(column.field()));
let schema = Schema::new_with_metadata(fields, self.0.schema_ref().metadata().clone());

let mut arrays = self.0.columns().to_vec();
Expand Down Expand Up @@ -360,11 +360,11 @@ impl PyRecordBatch {
&self,
py: Python,
i: usize,
field: PyField,
field: NameOrField,
column: PyArray,
) -> PyArrowResult<PyObject> {
let mut fields = self.0.schema_ref().fields().to_vec();
fields[i] = field.into_inner();
fields[i] = field.into_field(column.field());
let schema = Schema::new_with_metadata(fields, self.0.schema_ref().metadata().clone());

let mut arrays = self.0.columns().to_vec();
Expand Down

0 comments on commit e4f2b3a

Please sign in to comment.