`binary_mut` and `try_binary_mut` return `Ok` for an empty array whose buffer is shared

Aperta
#12,002 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #12012 di @abhinav-phi — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
data

Direzione di ricerca

Read arrow-arith/src/arity.rs around binary_mut and try_binary_mut, then compare their empty-array early returns with into_builder in arrow-array/src/array/primitive_array.rs and the unary helpers. First resolve which shared-buffer behavior the binary forms should follow; done means their behavior and rustdoc agree, with regression coverage for the empty shared-buffer case.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

The rustdoc of binary_mut says that if the buffer of a is shared, it returns Err(self), and try_binary_mut refers to it for buffer reuse. For an empty a, both return Ok(Ok(empty array)) even when the buffer is shared, because they return early before into_builder (the same in try_binary_mut). unary_mut and try_unary_mut call into_builder first, so they return Err(self) for the same input.

No buffer is changed, so this is a difference between the documentation and the behavior, and between the unary and binary forms.

To Reproduce

On main at 9ffd63d528:

use arrow::array::Int32Array;
use arrow::compute::{binary_mut, try_binary_mut, try_unary_mut, unary_mut};

let a = Int32Array::from(Vec::<i32>::new());
let b = Int32Array::from(Vec::<i32>::new());

// Err(self): the buffer is shared with `a`
assert!(unary_mut(a.clone(), |x| x + 1).is_err());
assert!(try_unary_mut(a.clone(), |x| Ok(x + 1)).is_err());

// Ok(Ok(empty)) instead of Err(self)
assert!(matches!(binary_mut(a.clone(), &b, |x, y| x + y), Ok(Ok(_))));
assert!(matches!(try_binary_mut(a.clone(), &b, |x, y| Ok(x + y)), Ok(Ok(_))));

Expected behavior

Should the binary forms return Err(self) for a shared buffer whatever its length, as the rustdoc says and the unary forms do? Or should all four return Ok for an empty array, and the rustdoc say so?

Additional context

Found by a property test of the arity helpers.

Lingua principale
Rust
Stelle
3.7k
Fork
1.5k
Merge medio
2g 16h
PR unite (30g)
183

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/arrow-rs

Tutte le issue di apache/arrow-rs

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.