observablehq / observablehq/plot

Determine length of column-oriented dataframe?

Open
#1,088 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement question
Dominant language
HTML
Stars
5.4k
Forks
244
PR merge metrics
No merged PRs in 30d

Description

Suppose the data is given as an object of columns:

df = {x: [1, 2, 3], y: [1, 2, 3]}

(This is how Quarto returns dataframes, and arquero does something similar.)

To use this in a mark we can call:

Plot.barX(data, {x: df.x, y: df.y, …)

But there is no good way to specify data:

  • if we specify it as {length: n} it will get materialized at some point, which is not optimal if the dataframe has millions of rows.
  • if we pass df.x as data, it is semantically incorrect
  • technically new Array(df.x.length) is fine, but it's a mental stretch

I wonder if we could have either: data = n (a number) —which would be read as new Array(n)—; or a special symbol that would say "use the channels' length". Another useful possibility would be for "dataframe objects" to have some sort of length property.

cc: @allisonhorst ; discussion after reading https://allisonhorst.github.io/posts/2022-10-14-bird-attacks/

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Plot.barX and other marks interpret the data argument when channels are supplied as column arrays. Compare the proposed number, symbol, and dataframe-length approaches, including the Quarto and arquero examples. Done means a documented, consistent way to specify column-oriented data without materializing millions of rows.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.