Skip to content

window transform: strict median/deviation/variance/pXX check missing values at the wrong rows when there are several series #2471

Open

Description

@trackoor

With strict: true, the median, deviation, variance and pXX window reducers look for missing values at the within-series position instead of the row index, so any series that does not occupy rows 0..n-1 (a second z series, a later facet) gets gaps in the wrong places.

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

const data = [
  {i: 0, v: 1, g: "a"}, {i: 1, v: 10,   g: "b"},
  {i: 2, v: 2, g: "a"}, {i: 3, v: null, g: "b"},
  {i: 4, v: 3, g: "a"}, {i: 5, v: 30,   g: "b"},
  {i: 6, v: 4, g: "a"}, {i: 7, v: 40,   g: "b"}
];

const o = Plot.windowY({k: 2, reduce: "median", strict: true, anchor: "end"}, {x: "i", y: "v", z: "g"});
o.transform(data, [Uint32Array.from(data, (_, i) => i)]);
console.log(Array.from(o.y.transform()));

node t.mjs

Actual:

[ undefined, undefined, 1.5, 10, 2.5, 30, NaN, NaN ]

Expected (what reduce: "mean" gives on the same data):

[ undefined, undefined, 1.5, NaN, 2.5, NaN, 3.5, 35 ]

Series "a" has no missing values but loses its last window, and series "b" gets values for the two windows that contain null.

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

In reduceAccessor in src/transforms/window.js, v takes a row index but the strict NaN counting calls v(i) and v(i + k - 1); it should be v(I[i]) and v(I[i + k - 1]).

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions