window transform: difference, ratio, first and last drop the trailing outputs of each series

Aperta Adatta ai principianti
#2,472 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, node.js

Direzione di ricerca

Leggi src/transforms/window.js ed esamina reduceDifference, reduceRatio, reduceFirst e reduceLast, confrontando i limiti dei loro cicli in modalità strict e non strict con il comportamento descritto negli esempi. Aggiungi o aggiorna i test per gli output finali in entrambe le modalità, quindi esegui i test pertinenti della trasformazione window. Il lavoro è completato quando questi reducer producono gli output completi previsti, incluse le finestre finali ritagliate quando strict è false.

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

Descrizione

The difference, ratio, first and last window reducers stop their loops early: with strict: true the last full window is missing, and with strict: false the last k - 1 - s truncated windows are missing. Other reducers such as mean fill these positions.

import * as Plot from "@observablehq/plot";

const run = (w, data) => {
  const o = Plot.windowY(w, {x: "i", y: "v"});
  o.transform(data, [Uint32Array.from(data, (_, i) => i)]);
  return Array.from(o.y.transform());
};
const d = [2, 4, 8, 16].map((v, i) => ({i, v}));

console.log(run({k: 2, reduce: "difference", strict: true, anchor: "end"}, d));
console.log(run({k: 2, reduce: "ratio",      strict: true, anchor: "end"}, d));
console.log(run({k: 1, reduce: "last",       strict: true}, d));
console.log(run({k: 3, reduce: "first",      anchor: "start"}, d));
console.log(run({k: 3, reduce: "difference", anchor: "start"}, d));
console.log(run({k: 3, reduce: "mean",       anchor: "start"}, d));

node t.mjs

Actual:

[ undefined, 2, 4, undefined ]
[ undefined, 2, 2, undefined ]
[ 2, 4, 8, undefined ]
[ 2, 4, undefined, undefined ]
[ 6, 12, undefined, undefined ]
[ 4.666666666666667, 9.333333333333334, 12, 16 ]

Expected:

[ undefined, 2, 4, 8 ]
[ undefined, 2, 2, 2 ]
[ 2, 4, 8, 16 ]
[ 2, 4, 8, 16 ]
[ 6, 12, 8, 0 ]
[ 4.666666666666667, 9.333333333333334, 12, 16 ]

In a chart, Plot.lineY(data, Plot.windowY({k: 7, reduce: "difference"}, ...)) stops short of the right edge.

Tested with @observablehq/plot 0.6.19 and main 2245188, Node.js v26.13.0.

In src/transforms/window.js, reduceDifference, reduceRatio, reduceFirst and reduceLast use n = I.length - k in the strict branch (should be I.length - k + 1) and n = I.length - k + s + 1 in the non-strict branch (should be I.length - s, with the window clipped to I.length).

Credit: https://ucsbplse.github.io/

Lingua principale
HTML
Stelle
5.4k
Fork
251
Merge medio
2g 1h
PR unite (30g)
2

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 observablehq/plot

Tutte le issue di observablehq/plot

Issue simili

Altre issue su Data Visualization

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.