Skip to content

Commit

Permalink
Use insta for dataframe snapshot tests (#8696)
Browse files Browse the repository at this point in the history
* Part of #3741 

This will make it easier to switch out TransportChunk for RecordBatch
  • Loading branch information
emilk authored Jan 15, 2025
1 parent 77d4f58 commit ec07b14
Show file tree
Hide file tree
Showing 28 changed files with 310 additions and 291 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5913,6 +5913,7 @@ version = "0.22.0-alpha.1+dev"
dependencies = [
"anyhow",
"arrow",
"insta",
"itertools 0.13.0",
"nohash-hasher",
"rayon",
Expand Down
8 changes: 3 additions & 5 deletions crates/store/re_chunk/src/arrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ impl TransportChunk {
/// related rust structures that refer to those data buffers.
pub fn try_to_arrow_record_batch(&self) -> Result<RecordBatch, ArrowError> {
let columns: Vec<_> = self
.all_columns()
.map(|(_field, arr2_array)| {
let data = arrow2::array::to_data(arr2_array.as_ref());
make_array(data)
})
.columns()
.iter()
.map(|arr2_array| make_array(arrow2::array::to_data(*arr2_array)))
.collect();

RecordBatch::try_new(self.schema(), columns)
Expand Down
14 changes: 8 additions & 6 deletions crates/store/re_chunk/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ impl TransportChunk {
/// * [`Self::FIELD_METADATA_VALUE_KIND_CONTROL`]
/// * [`Self::FIELD_METADATA_VALUE_KIND_DATA`]
#[inline]
pub fn columns<'a>(
fn columns_of_kind<'a>(
&'a self,
kind: &'a str,
) -> impl Iterator<Item = (&'a ArrowField, &'a Box<dyn Arrow2Array>)> + 'a {
Expand All @@ -402,7 +402,9 @@ impl TransportChunk {
}

#[inline]
pub fn all_columns(&self) -> impl Iterator<Item = (&ArrowField, &Box<dyn Arrow2Array>)> + '_ {
pub fn fields_and_columns(
&self,
) -> impl Iterator<Item = (&ArrowField, &Box<dyn Arrow2Array>)> + '_ {
self.schema
.fields
.iter()
Expand All @@ -416,26 +418,26 @@ impl TransportChunk {
}

#[inline]
pub fn all_columns_collected(&self) -> Vec<&dyn Arrow2Array> {
pub fn columns(&self) -> Vec<&dyn Arrow2Array> {
self.data.iter().map(|c| c.as_ref()).collect()
}

/// Iterates all control columns present in this chunk.
#[inline]
pub fn controls(&self) -> impl Iterator<Item = (&ArrowField, &Box<dyn Arrow2Array>)> {
self.columns(Self::FIELD_METADATA_VALUE_KIND_CONTROL)
self.columns_of_kind(Self::FIELD_METADATA_VALUE_KIND_CONTROL)
}

/// Iterates all data columns present in this chunk.
#[inline]
pub fn components(&self) -> impl Iterator<Item = (&ArrowField, &Box<dyn Arrow2Array>)> {
self.columns(Self::FIELD_METADATA_VALUE_KIND_DATA)
self.columns_of_kind(Self::FIELD_METADATA_VALUE_KIND_DATA)
}

/// Iterates all timeline columns present in this chunk.
#[inline]
pub fn timelines(&self) -> impl Iterator<Item = (&ArrowField, &Box<dyn Arrow2Array>)> {
self.columns(Self::FIELD_METADATA_VALUE_KIND_TIME)
self.columns_of_kind(Self::FIELD_METADATA_VALUE_KIND_TIME)
}

/// How many columns in total? Includes control, time, and component columns.
Expand Down
1 change: 1 addition & 0 deletions crates/store/re_dataframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ re_types_core.workspace = true
anyhow.workspace = true
arrow.workspace = true
arrow2.workspace = true
insta.workspace = true
itertools.workspace = true
nohash-hasher.workspace = true
rayon.workspace = true
Expand Down
Loading

0 comments on commit ec07b14

Please sign in to comment.