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

Abierto Apto para principiantes
#2,472 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
88/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
javascript, node.js

Línea de trabajo

Lee src/transforms/window.js e inspecciona reduceDifference, reduceRatio, reduceFirst y reduceLast. Compara los límites de sus bucles en modo estricto y no estricto con el comportamiento descrito en los ejemplos. Añade o actualiza pruebas para las salidas finales en ambos modos y luego ejecuta las pruebas pertinentes de la transformación window. Se considerará terminado cuando estos reducers produzcan las salidas completas esperadas, incluidas las ventanas finales recortadas cuando strict es false.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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/

Lenguaje dominante
HTML
Estrellas
5.4k
Forks
251
Merge medio
2 d 1 h
PR fusionados (30 d)
2

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de observablehq/plot

Todos los issues de observablehq/plot

Issues similares

Más issues de Data Visualization

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.