Skip to content

Commit 830cd1e

Browse files
committed
fix
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent d9e1f57 commit 830cd1e

File tree

28 files changed

+192
-139
lines changed

28 files changed

+192
-139
lines changed

Cargo.lock

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

encodings/alp/src/alp/compress.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ mod tests {
158158
let array = PrimitiveArray::from_option_iter([None, Some(1.234f32), None]);
159159
let encoded = alp_encode(&array, None).unwrap();
160160
assert!(encoded.patches().is_none());
161-
let expected_encoded = PrimitiveArray::from_iter(vec![0i32, 1234, 0]);
161+
let expected_encoded = PrimitiveArray::from_option_iter([None, Some(1234i32), None]);
162162
assert_arrays_eq!(encoded.encoded(), expected_encoded);
163163
assert_eq!(encoded.exponents(), Exponents { e: 9, f: 6 });
164164

165165
let decoded = decompress(&encoded);
166-
let expected = PrimitiveArray::from_iter(vec![0f32, 1.234f32, 0f32]);
166+
let expected = PrimitiveArray::from_option_iter(vec![None, Some(1.234f32), None]);
167167
assert_arrays_eq!(decoded, expected);
168168
}
169169

@@ -190,7 +190,8 @@ mod tests {
190190
let array = PrimitiveArray::new(values, Validity::from_iter([true, true, false, true]));
191191
let encoded = alp_encode(&array, None).unwrap();
192192
assert!(encoded.patches().is_none());
193-
let expected_encoded = PrimitiveArray::from_iter(vec![1234i64, 2718, 1234, 4000]);
193+
let expected_encoded =
194+
PrimitiveArray::from_option_iter(buffer![Some(1234i64), Some(2718), None, Some(4000)]);
194195
assert_arrays_eq!(encoded.encoded(), expected_encoded);
195196
assert_eq!(encoded.exponents(), Exponents { e: 16, f: 13 });
196197

encodings/alp/src/alp/compute/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ register_kernel!(CastKernelAdapter(ALPVTable).lift());
4545
#[cfg(test)]
4646
mod tests {
4747
use rstest::rstest;
48-
use vortex_array::IntoArray;
4948
use vortex_array::arrays::PrimitiveArray;
5049
use vortex_array::compute::cast;
5150
use vortex_array::compute::conformance::cast::test_cast_conformance;
51+
use vortex_array::{IntoArray, assert_arrays_eq};
5252
use vortex_buffer::buffer;
5353
use vortex_dtype::{DType, Nullability, PType};
5454

@@ -98,7 +98,7 @@ mod tests {
9898
);
9999

100100
let decoded = casted.to_canonical().into_primitive();
101-
assert_eq!(decoded.as_slice::<i32>(), &[1i32, 2, 3, 4]);
101+
assert_arrays_eq!(decoded, PrimitiveArray::from_iter([1i32, 2, 3, 4]));
102102
}
103103

104104
#[rstest]

encodings/alp/src/alp_rd/array.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ impl CanonicalVTable<ALPRDVTable> for ALPRDVTable {
265265
#[cfg(test)]
266266
mod test {
267267
use rstest::rstest;
268-
use vortex_array::ToCanonical;
269268
use vortex_array::arrays::PrimitiveArray;
269+
use vortex_array::{ToCanonical, assert_arrays_eq};
270270

271271
use crate::{ALPRDFloat, alp_rd};
272272

@@ -294,7 +294,6 @@ mod test {
294294

295295
let decoded = rd_array.to_primitive();
296296

297-
let maybe_null_reals: Vec<T> = reals.into_iter().map(|v| v.unwrap_or_default()).collect();
298-
assert_eq!(decoded.as_slice::<T>(), &maybe_null_reals);
297+
assert_arrays_eq!(decoded, PrimitiveArray::from_option_iter(reals));
299298
}
300299
}

encodings/alp/src/alp_rd/compute/filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ mod test {
3737
use vortex_array::compute::conformance::filter::test_filter_conformance;
3838
use vortex_array::compute::filter;
3939
use vortex_array::validity::Validity;
40-
use vortex_array::{IntoArray, ToCanonical};
40+
use vortex_array::{IntoArray, ToCanonical, assert_arrays_eq};
4141
use vortex_buffer::buffer;
4242
use vortex_mask::Mask;
4343

@@ -57,7 +57,7 @@ mod test {
5757
let filtered = filter(encoded.as_ref(), &Mask::from_iter([true, false, true]))
5858
.unwrap()
5959
.to_primitive();
60-
assert_eq!(filtered.as_slice::<T>(), &[a, outlier]);
60+
assert_arrays_eq!(filtered, PrimitiveArray::from_iter([a, outlier]));
6161
}
6262

6363
#[rstest]

encodings/alp/src/alp_rd/compute/take.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ register_kernel!(TakeKernelAdapter(ALPRDVTable).lift());
4848
#[cfg(test)]
4949
mod test {
5050
use rstest::rstest;
51-
use vortex_array::ToCanonical;
5251
use vortex_array::arrays::PrimitiveArray;
5352
use vortex_array::compute::conformance::take::test_take_conformance;
5453
use vortex_array::compute::take;
54+
use vortex_array::{ToCanonical, assert_arrays_eq};
5555

5656
use crate::{ALPRDFloat, RDEncoder};
5757

@@ -78,7 +78,7 @@ mod test {
7878
.unwrap()
7979
.to_primitive();
8080

81-
assert_eq!(taken.as_slice::<T>(), &[a, outlier]);
81+
assert_arrays_eq!(taken, PrimitiveArray::from_iter([a, outlier]));
8282
}
8383

8484
#[rstest]
@@ -104,9 +104,10 @@ mod test {
104104
.unwrap()
105105
.to_primitive();
106106

107-
assert_eq!(taken.as_slice::<T>()[0], a);
108-
assert_eq!(taken.as_slice::<T>()[1], outlier);
109-
assert!(!taken.validity_mask().value(2));
107+
assert_arrays_eq!(
108+
taken,
109+
PrimitiveArray::from_option_iter([Some(a), Some(outlier), None])
110+
);
110111
}
111112

112113
#[rstest]

encodings/decimal-byte-parts/src/decimal_byte_parts/compute/compare.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ mod tests {
148148

149149
let res = compare(lhs.as_ref(), rhs.as_ref(), Operator::Eq).unwrap();
150150

151-
let expected = BoolArray::from_iter([false, false, true]).into_array();
151+
let expected = BoolArray::from_iter([Some(false), Some(false), Some(true)]).into_array();
152152
assert_arrays_eq!(res, expected);
153153
}
154154

@@ -202,15 +202,15 @@ mod tests {
202202
);
203203

204204
let res = compare(lhs.as_ref(), rhs.as_ref(), Operator::Eq).unwrap();
205-
let expected = BoolArray::from_iter([false, false, false]).into_array();
205+
let expected = BoolArray::from_iter([Some(false), Some(false), Some(false)]).into_array();
206206
assert_arrays_eq!(res, expected);
207207

208208
let res = compare(lhs.as_ref(), rhs.as_ref(), Operator::Gt).unwrap();
209-
let expected = BoolArray::from_iter([true, true, true]).into_array();
209+
let expected = BoolArray::from_iter([Some(true), Some(true), Some(true)]).into_array();
210210
assert_arrays_eq!(res, expected);
211211

212212
let res = compare(lhs.as_ref(), rhs.as_ref(), Operator::Lt).unwrap();
213-
let expected = BoolArray::from_iter([false, false, false]).into_array();
213+
let expected = BoolArray::from_iter([Some(false), Some(false), Some(false)]).into_array();
214214
assert_arrays_eq!(res, expected);
215215

216216
// This cannot be converted to a i32.
@@ -220,15 +220,15 @@ mod tests {
220220
);
221221

222222
let res = compare(lhs.as_ref(), rhs.as_ref(), Operator::Eq).unwrap();
223-
let expected = BoolArray::from_iter([false, false, false]).into_array();
223+
let expected = BoolArray::from_iter([Some(false), Some(false), Some(false)]).into_array();
224224
assert_arrays_eq!(res, expected);
225225

226226
let res = compare(lhs.as_ref(), rhs.as_ref(), Operator::Gt).unwrap();
227-
let expected = BoolArray::from_iter([false, false, false]).into_array();
227+
let expected = BoolArray::from_iter([Some(false), Some(false), Some(false)]).into_array();
228228
assert_arrays_eq!(res, expected);
229229

230230
let res = compare(lhs.as_ref(), rhs.as_ref(), Operator::Lt).unwrap();
231-
let expected = BoolArray::from_iter([true, true, true]).into_array();
231+
let expected = BoolArray::from_iter([Some(true), Some(true), Some(true)]).into_array();
232232
assert_arrays_eq!(res, expected);
233233
}
234234
}

encodings/dict/src/compute/cast.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod tests {
3838
use vortex_array::arrays::PrimitiveArray;
3939
use vortex_array::compute::cast;
4040
use vortex_array::compute::conformance::cast::test_cast_conformance;
41-
use vortex_array::{IntoArray, ToCanonical};
41+
use vortex_array::{IntoArray, ToCanonical, assert_arrays_eq};
4242
use vortex_buffer::buffer;
4343
use vortex_dtype::{DType, Nullability, PType};
4444

@@ -61,7 +61,7 @@ mod tests {
6161
);
6262

6363
let decoded = casted.to_primitive();
64-
assert_eq!(decoded.as_slice::<i64>(), &[1i64, 2, 3, 2, 1]);
64+
assert_arrays_eq!(decoded, PrimitiveArray::from_iter([1i64, 2, 3, 2, 1]));
6565
}
6666

6767
#[test]
@@ -163,10 +163,7 @@ mod tests {
163163
// Verify values are unchanged
164164
let original_values = dict.to_primitive();
165165
let final_values = back_dict.to_primitive();
166-
assert_eq!(
167-
original_values.as_slice::<i32>(),
168-
final_values.as_slice::<i32>()
169-
);
166+
assert_arrays_eq!(original_values, final_values);
170167
}
171168

172169
#[rstest]

encodings/dict/src/compute/fill_null.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mod tests {
5353
use vortex_array::arrays::PrimitiveArray;
5454
use vortex_array::compute::fill_null;
5555
use vortex_array::validity::Validity;
56-
use vortex_array::{IntoArray, ToCanonical};
56+
use vortex_array::{IntoArray, ToCanonical, assert_arrays_eq};
5757
use vortex_buffer::{BitBuffer, buffer};
5858
use vortex_dtype::Nullability;
5959
use vortex_error::VortexUnwrap;
@@ -79,7 +79,7 @@ mod tests {
7979
)
8080
.vortex_unwrap();
8181
let filled_primitive = filled.to_primitive();
82-
assert_eq!(filled_primitive.as_slice::<i32>(), [10, 20, 20]);
82+
assert_arrays_eq!(filled_primitive, PrimitiveArray::from_iter([10, 20, 20]));
8383
assert!(filled_primitive.all_valid());
8484
}
8585
}

encodings/fastlanes/src/bitpacking/compress.rs

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ pub mod test_harness {
563563
mod test {
564564
use rand::SeedableRng as _;
565565
use rand::rngs::StdRng;
566-
use vortex_array::ToCanonical as _;
567566
use vortex_array::arrays::ChunkedArray;
567+
use vortex_array::{ToCanonical as _, assert_arrays_eq};
568568
use vortex_buffer::{Buffer, buffer};
569569
use vortex_dtype::Nullability;
570570
use vortex_error::VortexError;
@@ -578,26 +578,23 @@ mod test {
578578
let zeros = buffer![0u16, 0, 0, 0].into_array().to_primitive();
579579
let bitpacked = bitpack_encode(&zeros, 0, None).unwrap();
580580
let actual = unpack(&bitpacked);
581-
let actual = actual.as_slice::<u16>();
582-
assert_eq!(actual, &[0u16, 0, 0, 0]);
581+
assert_arrays_eq!(actual, PrimitiveArray::from_iter([0u16, 0, 0, 0]));
583582
}
584583

585584
#[test]
586585
fn test_simple_patches() {
587586
let zeros = buffer![0u16, 1, 0, 1].into_array().to_primitive();
588587
let bitpacked = bitpack_encode(&zeros, 0, None).unwrap();
589588
let actual = unpack(&bitpacked);
590-
let actual = actual.as_slice::<u16>();
591-
assert_eq!(actual, &[0u16, 1, 0, 1]);
589+
assert_arrays_eq!(actual, PrimitiveArray::from_iter([0u16, 1, 0, 1]));
592590
}
593591

594592
#[test]
595593
fn test_one_full_chunk() {
596594
let zeros = BufferMut::from_iter(0u16..1024).into_array().to_primitive();
597595
let bitpacked = bitpack_encode(&zeros, 10, None).unwrap();
598596
let actual = unpack(&bitpacked);
599-
let actual = actual.as_slice::<u16>();
600-
assert_eq!(actual, &(0u16..1024).collect::<Vec<_>>());
597+
assert_arrays_eq!(actual, PrimitiveArray::from_iter(0u16..1024));
601598
}
602599

603600
#[test]
@@ -608,13 +605,9 @@ mod test {
608605
let bitpacked = bitpack_encode(&zeros, 10, None).unwrap();
609606
assert!(bitpacked.patches().is_some());
610607
let actual = unpack(&bitpacked);
611-
let actual = actual.as_slice::<u16>();
612-
assert_eq!(
608+
assert_arrays_eq!(
613609
actual,
614-
&(5u16..1029)
615-
.chain(5u16..1029)
616-
.chain(5u16..1029)
617-
.collect::<Vec<_>>()
610+
PrimitiveArray::from_iter((5u16..1029).chain(5u16..1029).chain(5u16..1029))
618611
);
619612
}
620613

@@ -624,8 +617,7 @@ mod test {
624617
let bitpacked = bitpack_encode(&zeros, 11, None).unwrap();
625618
assert!(bitpacked.patches().is_none());
626619
let actual = unpack(&bitpacked);
627-
let actual = actual.as_slice::<u16>();
628-
assert_eq!(actual, &(0u16..1025).collect::<Vec<_>>());
620+
assert_arrays_eq!(actual, PrimitiveArray::from_iter(0u16..1025));
629621
}
630622

631623
#[test]
@@ -637,8 +629,7 @@ mod test {
637629
assert_eq!(bitpacked.len(), 1025);
638630
assert!(bitpacked.patches().is_some());
639631
let actual = unpack(&bitpacked);
640-
let actual = actual.as_slice::<u16>();
641-
assert_eq!(actual, &(512u16..1537).collect::<Vec<_>>());
632+
assert_arrays_eq!(actual, PrimitiveArray::from_iter(512u16..1537));
642633
}
643634

644635
#[test]
@@ -651,8 +642,7 @@ mod test {
651642
assert!(bitpacked.patches().is_some());
652643
let bitpacked = bitpacked.slice(1023..1025);
653644
let actual = unpack(bitpacked.as_::<BitPackedVTable>());
654-
let actual = actual.as_slice::<u16>();
655-
assert_eq!(actual, &[1535, 1536]);
645+
assert_arrays_eq!(actual, PrimitiveArray::from_iter([1535u16, 1536]));
656646
}
657647

658648
#[test]
@@ -665,8 +655,10 @@ mod test {
665655
assert!(bitpacked.patches().is_some());
666656
let bitpacked = bitpacked.slice(1023..2049);
667657
let actual = unpack(bitpacked.as_::<BitPackedVTable>());
668-
let actual = actual.as_slice::<u16>();
669-
assert_eq!(actual, &(1023..2049).map(|x| x + 512).collect::<Vec<_>>());
658+
assert_arrays_eq!(
659+
actual,
660+
PrimitiveArray::from_iter((1023u16..2049).map(|x| x + 512))
661+
);
670662
}
671663

672664
#[test]
@@ -717,7 +709,7 @@ mod test {
717709
let values = PrimitiveArray::from_iter((0..n).map(|i| (i % 2047) as u16));
718710
let compressed = BitPackedArray::encode(values.as_ref(), 11).unwrap();
719711
let decompressed = compressed.to_primitive();
720-
assert_eq!(decompressed.as_slice::<u16>(), values.as_slice::<u16>());
712+
assert_arrays_eq!(decompressed, values);
721713

722714
values
723715
.as_slice::<u16>()
@@ -754,20 +746,14 @@ mod test {
754746
chunked.clone().append_to_builder(&mut primitive_builder);
755747
let ca_into = primitive_builder.finish();
756748

757-
assert_eq!(
758-
into_ca.as_slice::<i32>(),
759-
ca_into.to_primitive().as_slice::<i32>()
760-
);
749+
assert_arrays_eq!(into_ca, ca_into.to_primitive());
761750

762751
let mut primitive_builder =
763752
PrimitiveBuilder::<i32>::with_capacity(chunked.dtype().nullability(), 10 * 100);
764753
primitive_builder.extend_from_array(&chunked);
765754
let ca_into = primitive_builder.finish();
766755

767-
assert_eq!(
768-
into_ca.as_slice::<i32>(),
769-
ca_into.to_primitive().as_slice::<i32>()
770-
);
756+
assert_arrays_eq!(into_ca, ca_into.to_primitive());
771757
}
772758

773759
#[test]
@@ -835,7 +821,7 @@ mod test {
835821
let result = builder.finish_into_primitive();
836822

837823
// Verify all values were correctly unpacked including patches.
838-
assert_eq!(result.as_slice::<u32>(), &values);
824+
assert_arrays_eq!(result, PrimitiveArray::from_iter(values));
839825
}
840826

841827
#[test]
@@ -858,7 +844,7 @@ mod test {
858844
// chunk 1 (1024-2047): no patches -> points to patch index 2
859845
// chunk 2 (2048-3071): patch at 3000 -> starts at patch index 2
860846
// chunk 3 (3072-4095): patch at 3100 -> starts at patch index 3
861-
assert_eq!(chunk_offsets.as_slice::<u64>(), &[0, 2, 2, 3]);
847+
assert_arrays_eq!(chunk_offsets, PrimitiveArray::from_iter([0u64, 2, 2, 3]));
862848
}
863849

864850
#[test]
@@ -877,7 +863,7 @@ mod test {
877863
let patches = bitpacked.patches().unwrap();
878864
let chunk_offsets = patches.chunk_offsets().as_ref().unwrap().to_primitive();
879865

880-
assert_eq!(chunk_offsets.as_slice::<u64>(), &[0, 2, 2]);
866+
assert_arrays_eq!(chunk_offsets, PrimitiveArray::from_iter([0u64, 2, 2]));
881867
}
882868

883869
#[test]
@@ -901,7 +887,7 @@ mod test {
901887
// chunk 2 (2048-3071): no patches -> points to patch index 3
902888
// chunk 3 (3072-4095): no patches -> points to patch index 3 (remaining chunks filled)
903889
// chunk 4 (4096-5119): no patches -> points to patch index 3 (remaining chunks filled)
904-
assert_eq!(chunk_offsets.as_slice::<u64>(), &[0, 2, 3, 3, 3]);
890+
assert_arrays_eq!(chunk_offsets, PrimitiveArray::from_iter([0u64, 2, 3, 3, 3]));
905891
}
906892

907893
#[test]
@@ -921,6 +907,6 @@ mod test {
921907
let chunk_offsets = patches.chunk_offsets().as_ref().unwrap().to_primitive();
922908

923909
// Single chunk starting at patch index 0.
924-
assert_eq!(chunk_offsets.as_slice::<u64>(), &[0]);
910+
assert_arrays_eq!(chunk_offsets, PrimitiveArray::from_iter([0u64]));
925911
}
926912
}

0 commit comments

Comments
 (0)