Skip to content

Commit 5aca703

Browse files
wjones127claude
andauthored
chore: remove custom cast_with_options in favor of upstream (#6344)
`arrow-cast` 57.0.0 added native support for `FixedSizeList → FixedSizeList` casting, which was the only reason `lance_arrow::cast::cast_with_options` existed. This removes the wrapper and updates all call sites to use `arrow_cast::cast_with_options` directly. --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e7369fb commit 5aca703

10 files changed

Lines changed: 20 additions & 42 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ crate-type = ["cdylib"]
1515
[dependencies]
1616
arrow = { version = "57.0.0", features = ["pyarrow"] }
1717
arrow-array = "57.0.0"
18+
arrow-cast = "57.0.0"
1819
arrow-data = "57.0.0"
1920
arrow-schema = "57.0.0"
2021
object_store = "0.12.4"

python/src/dataset.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use arrow::ffi_stream::ArrowArrayStreamReader;
1212
use arrow::pyarrow::*;
1313
use arrow_array::Array;
1414
use arrow_array::{RecordBatch, RecordBatchReader, make_array};
15+
use arrow_cast::cast_with_options;
1516
use arrow_data::ArrayData;
1617
use arrow_schema::{DataType, Schema as ArrowSchema};
1718
use async_trait::async_trait;
@@ -3610,14 +3611,13 @@ fn prepare_vector_index_params(
36103611
// as the vectors that will be indexed.
36113612
let mut centroids: Arc<dyn Array> = batch.column(0).clone();
36123613
if centroids.data_type() != column_type {
3613-
centroids = lance_arrow::cast::cast_with_options(
3614-
centroids.as_ref(),
3615-
column_type,
3616-
&Default::default(),
3617-
)
3618-
.map_err(|e| {
3619-
PyValueError::new_err(format!("Failed to cast centroids to column type: {}", e))
3620-
})?;
3614+
centroids = cast_with_options(centroids.as_ref(), column_type, &Default::default())
3615+
.map_err(|e| {
3616+
PyValueError::new_err(format!(
3617+
"Failed to cast centroids to column type: {}",
3618+
e
3619+
))
3620+
})?;
36213621
}
36223622
let centroids = as_fixed_size_list_array(centroids.as_ref());
36233623

rust/lance-arrow/src/cast.rs

Lines changed: 0 additions & 30 deletions
This file was deleted.

rust/lance-arrow/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ pub mod floats;
3030
use crate::list::ListArrayExt;
3131
pub use floats::*;
3232

33-
pub mod cast;
3433
pub mod ipc;
3534
pub mod json;
3635
pub mod list;

rust/lance-datafusion/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ version.workspace = true
1313
arrow = {workspace = true, features = ["ffi"]}
1414
arrow-array = {workspace = true, features = ["ffi"]}
1515
arrow-buffer.workspace = true
16+
arrow-cast.workspace = true
1617
arrow-ord.workspace = true
1718
arrow-schema.workspace = true
1819
arrow-select.workspace = true

rust/lance-datafusion/src/planner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::sql::{parse_sql_expr, parse_sql_filter};
1414
use arrow::compute::CastOptions;
1515
use arrow_array::ListArray;
1616
use arrow_buffer::OffsetBuffer;
17+
use arrow_cast::cast_with_options;
1718
use arrow_schema::{DataType as ArrowDataType, Field, SchemaRef, TimeUnit};
1819
use arrow_select::concat::concat;
1920
use datafusion::common::DFSchema;
@@ -45,7 +46,6 @@ use datafusion::{
4546
scalar::ScalarValue,
4647
};
4748
use datafusion_functions::core::getfield::GetFieldFunc;
48-
use lance_arrow::cast::cast_with_options;
4949
use lance_core::datatypes::Schema;
5050
use lance_core::error::LanceOptionExt;
5151

rust/lance/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ lance-geo = { workspace = true, optional = true }
3030
arrow-arith = { workspace = true }
3131
arrow-array = { workspace = true }
3232
arrow-buffer = { workspace = true }
33+
arrow-cast = { workspace = true }
3334
arrow-ipc = { workspace = true }
3435
arrow-ord = { workspace = true }
3536
arrow-row = { workspace = true }

rust/lance/src/dataset/schema_evolution.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{Error, Result, io::exec::Planner};
1212
use arrow::compute::CastOptions;
1313
use arrow::compute::can_cast_types;
1414
use arrow_array::{Array, RecordBatch, RecordBatchReader};
15+
use arrow_cast::cast_with_options;
1516
use arrow_schema::{DataType, Field as ArrowField, Schema as ArrowSchema};
1617
use datafusion::execution::SendableRecordBatchStream;
1718
use futures::stream::{StreamExt, TryStreamExt};
@@ -635,7 +636,7 @@ pub(super) async fn alter_columns(
635636
let mut columns = Vec::with_capacity(batch.num_columns());
636637
for (old, new) in &cast_fields {
637638
let old_column = batch[&old.name].clone();
638-
let new_column = lance_arrow::cast::cast_with_options(
639+
let new_column = cast_with_options(
639640
&old_column,
640641
&new.data_type(),
641642
// Safe: false means it will error if the cast is lossy.
@@ -1963,7 +1964,7 @@ mod test {
19631964
Arc::new(Float16Array::from_iter_values(
19641965
(0..nrows).map(|i| f16::from_f32(i as f32)),
19651966
)),
1966-
lance_arrow::cast::cast_with_options(
1967+
cast_with_options(
19671968
batch["vec"].as_ref(),
19681969
&DataType::FixedSizeList(
19691970
Arc::new(ArrowField::new("item", DataType::Float16, true)),

0 commit comments

Comments
 (0)