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

オープン 初心者向け
#2,472 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
88/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js

調査の方向性

src/transforms/window.js を読み、reduceDifference、reduceRatio、reduceFirst、reduceLast を調べて、strict モードと non-strict モードでのループ境界を例に記載された動作と比較してください。両モードの末尾の出力に対するテストを追加または更新し、関連する window transform のテストを実行してください。strict が false の場合の末尾の切り詰められたウィンドウも含め、これらの reducer が期待される全長の出力を生成すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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/

主要言語
HTML
スター
5.4k
フォーク
251
平均マージ
2日 1時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

observablehq/plot のほかの issue

observablehq/plot の issue をすべて見る

似ている issue

Data Visualization の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。