Skip to content

Commit de9af5f

Browse files
committed
Replace deprecated true_count in tests with explicit-context sum
Instead of silencing the `BoolTyped::true_count` deprecation with `#[allow(deprecated)]`, drop the deprecated call entirely in the `datetime-parts` and `onpair` tests. Each now counts true values via `sum(array, ctx)` with an explicit `ExecutionCtx`: - `datetime-parts` compare/rules tests gain a small `true_count` helper that builds the context from `LEGACY_SESSION` (matching the surrounding tests). - The `onpair` smoke test reuses its existing empty-`SESSION` context. This removes the last downstream uses of the deprecated API. Verified with `RUSTFLAGS="-D deprecated" cargo build --all-targets` and by running both crates' tests. Signed-off-by: Claude <noreply@anthropic.com>
1 parent 4236f98 commit de9af5f

3 files changed

Lines changed: 46 additions & 19 deletions

File tree

encodings/datetime-parts/src/compute/compare.rs

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,12 @@ fn compare_dtp(
200200
}
201201

202202
#[cfg(test)]
203-
#[allow(deprecated)]
204203
mod test {
205204
use rstest::rstest;
205+
use vortex_array::ArrayRef;
206206
use vortex_array::LEGACY_SESSION;
207207
use vortex_array::VortexSessionExecute;
208+
use vortex_array::aggregate_fn::fns::sum::sum;
208209
use vortex_array::arrays::PrimitiveArray;
209210
use vortex_array::arrays::TemporalArray;
210211
use vortex_array::dtype::IntegerPType;
@@ -231,6 +232,16 @@ mod test {
231232
.expect("Failed to construct DateTimePartsArray from TemporalArray")
232233
}
233234

235+
/// Count the true values in a boolean array using an explicit execution context.
236+
fn true_count(array: &ArrayRef) -> usize {
237+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
238+
sum(array, &mut ctx)
239+
.unwrap()
240+
.as_primitive()
241+
.as_::<usize>()
242+
.unwrap()
243+
}
244+
234245
#[rstest]
235246
#[case(Validity::NonNullable, Validity::NonNullable)]
236247
#[case(Validity::NonNullable, Validity::AllValid)]
@@ -244,14 +255,14 @@ mod test {
244255
.into_array()
245256
.binary(rhs.into_array(), Operator::Eq)
246257
.unwrap();
247-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 1);
258+
assert_eq!(true_count(&comparison), 1);
248259

249260
let rhs = dtp_array_from_timestamp(0i64, rhs_validity); // January 1, 1970, 00:00:00 UTC
250261
let comparison = lhs
251262
.into_array()
252263
.binary(rhs.into_array(), Operator::Eq)
253264
.unwrap();
254-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 0);
265+
assert_eq!(true_count(&comparison), 0);
255266
}
256267

257268
#[rstest]
@@ -267,14 +278,14 @@ mod test {
267278
.into_array()
268279
.binary(rhs.into_array(), Operator::NotEq)
269280
.unwrap();
270-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 1);
281+
assert_eq!(true_count(&comparison), 1);
271282

272283
let rhs = dtp_array_from_timestamp(86400i64, rhs_validity); // January 2, 1970, 00:00:00 UTC
273284
let comparison = lhs
274285
.into_array()
275286
.binary(rhs.into_array(), Operator::NotEq)
276287
.unwrap();
277-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 0);
288+
assert_eq!(true_count(&comparison), 0);
278289
}
279290

280291
#[rstest]
@@ -290,7 +301,7 @@ mod test {
290301
.into_array()
291302
.binary(rhs.into_array(), Operator::Lt)
292303
.unwrap();
293-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 1);
304+
assert_eq!(true_count(&comparison), 1);
294305
}
295306

296307
#[rstest]
@@ -306,7 +317,7 @@ mod test {
306317
.into_array()
307318
.binary(rhs.into_array(), Operator::Gt)
308319
.unwrap();
309-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 1);
320+
assert_eq!(true_count(&comparison), 1);
310321
}
311322

312323
#[rstest]
@@ -340,27 +351,27 @@ mod test {
340351
.into_array()
341352
.binary(rhs.clone().into_array(), Operator::Eq)
342353
.unwrap();
343-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 0);
354+
assert_eq!(true_count(&comparison), 0);
344355

345356
let comparison = lhs
346357
.clone()
347358
.into_array()
348359
.binary(rhs.clone().into_array(), Operator::NotEq)
349360
.unwrap();
350-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 1);
361+
assert_eq!(true_count(&comparison), 1);
351362

352363
let comparison = lhs
353364
.clone()
354365
.into_array()
355366
.binary(rhs.clone().into_array(), Operator::Lt)
356367
.unwrap();
357-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 1);
368+
assert_eq!(true_count(&comparison), 1);
358369

359370
let comparison = lhs
360371
.into_array()
361372
.binary(rhs.into_array(), Operator::Lte)
362373
.unwrap();
363-
assert_eq!(comparison.as_bool_typed().true_count().unwrap(), 1);
374+
assert_eq!(true_count(&comparison), 1);
364375

365376
// `CompareOperator::Gt` and `CompareOperator::Gte` only cover the case of all lhs values
366377
// being larger. Therefore, these cases are not covered by unit tests.

encodings/datetime-parts/src/compute/rules.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,11 @@ fn is_constant_zero(array: &ArrayRef) -> bool {
178178
}
179179

180180
#[cfg(test)]
181-
#[allow(deprecated)]
182181
mod tests {
182+
use vortex_array::ArrayRef;
183183
use vortex_array::LEGACY_SESSION;
184184
use vortex_array::VortexSessionExecute;
185+
use vortex_array::aggregate_fn::fns::sum::sum;
185186
use vortex_array::arrays::PrimitiveArray;
186187
use vortex_array::arrays::TemporalArray;
187188
use vortex_array::arrays::scalar_fn::ScalarFnFactoryExt;
@@ -201,6 +202,16 @@ mod tests {
201202

202203
const SECONDS_PER_DAY: i64 = 86400;
203204

205+
/// Count the true values in a boolean array using an explicit execution context.
206+
fn true_count(array: &ArrayRef) -> usize {
207+
let mut ctx = LEGACY_SESSION.create_execution_ctx();
208+
sum(array, &mut ctx)
209+
.unwrap()
210+
.as_primitive()
211+
.as_::<usize>()
212+
.unwrap()
213+
}
214+
204215
/// Create a DTP array with the given day values (all at midnight).
205216
fn dtp_at_midnight(days: &[i64], time_unit: TimeUnit) -> DateTimePartsArray {
206217
let multiplier = match time_unit {
@@ -286,7 +297,7 @@ mod tests {
286297
);
287298

288299
// Verify correctness: days [0, 1, 2] <= 1 should give [true, true, false]
289-
assert_eq!(optimized.as_bool_typed().true_count().unwrap(), 2);
300+
assert_eq!(true_count(&optimized), 2);
290301
}
291302

292303
#[test]
@@ -314,7 +325,7 @@ mod tests {
314325
let optimized = between.optimize().unwrap();
315326

316327
// Verify correctness: days [0, 1, 2, 3, 4] between 1 and 3 should give [false, true, true, true, false]
317-
assert_eq!(optimized.as_bool_typed().true_count().unwrap(), 3);
328+
assert_eq!(true_count(&optimized), 3);
318329
}
319330

320331
#[test]
@@ -336,7 +347,7 @@ mod tests {
336347
// (optimization doesn't apply, so we keep the original structure)
337348
// Just verify it still computes correctly
338349
// days [0, 1, 2] at midnight <= day 1 at noon: [true, true, false]
339-
assert_eq!(optimized.as_bool_typed().true_count().unwrap(), 2);
350+
assert_eq!(true_count(&optimized), 2);
340351
}
341352

342353
#[test]
@@ -367,6 +378,6 @@ mod tests {
367378
// Should still compute correctly (just not optimized via pushdown)
368379
let optimized = comparison.optimize().unwrap();
369380
// timestamps at 1am on days [0, 1, 2] <= day 1 midnight: [true, false, false]
370-
assert_eq!(optimized.as_bool_typed().true_count().unwrap(), 1);
381+
assert_eq!(true_count(&optimized), 1);
371382
}
372383
}

encodings/experimental/onpair/tests/big_data.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
clippy::cast_possible_truncation,
1010
clippy::redundant_clone,
1111
clippy::tests_outside_test_module,
12-
clippy::use_debug,
13-
deprecated
12+
clippy::use_debug
1413
)]
1514

1615
use std::sync::LazyLock;
@@ -19,6 +18,7 @@ use std::time::Instant;
1918
use vortex_array::IntoArray;
2019
use vortex_array::VortexSessionExecute;
2120
use vortex_array::accessor::ArrayAccessor;
21+
use vortex_array::aggregate_fn::fns::sum::sum;
2222
use vortex_array::arrays::ConstantArray;
2323
use vortex_array::arrays::VarBinArray;
2424
use vortex_array::arrays::VarBinViewArray;
@@ -122,6 +122,11 @@ fn smoke_100k_rows() {
122122
.execute::<vortex_array::Canonical>(&mut ctx)
123123
.unwrap()
124124
.into_array();
125-
assert_eq!(eq.as_bool_typed().true_count().unwrap(), want_eq);
125+
let eq_count = sum(&eq, &mut ctx)
126+
.unwrap()
127+
.as_primitive()
128+
.as_::<usize>()
129+
.unwrap();
130+
assert_eq!(eq_count, want_eq);
126131
eprintln!("eq pushdown matches reference count ({})", want_eq);
127132
}

0 commit comments

Comments
 (0)