Skip to content

Commit

Permalink
fix apache arrow dates (alternative to #2096)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Jun 26, 2024
1 parent 932186c commit 1f5ded9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@types/node": "^20.5.0",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
"apache-arrow": "^15.0.2",
"apache-arrow": "^16.0.2",
"c8": "^9.1.0",
"canvas": "^2.0.0",
"d3-geo-projection": "^4.0.0",
Expand Down
8 changes: 7 additions & 1 deletion src/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,13 @@ function isArrowTable(data) {

// Extract columnar data
function columnar(data, name, type) {
return isArrowTable(data) ? maybeTypedArrayify(data.getChild(name), type) : maybeTypedMap(data, field(name), type);
if (isArrowTable(data)) {
const column = maybeTypedArrayify(data.getChild(name), type);
if (Array.isArray(column) && String(data.schema?.fields?.find((d) => d.name === name)).endsWith("<MILLISECOND>"))
column.find((d, i) => d != null && (column[i] = new Date(d)));
return column;
}
return maybeTypedMap(data, field(name), type);
}

// Arrayify arrow tables. We try to avoid materializing the values, but the
Expand Down
9 changes: 9 additions & 0 deletions test/plots/arrow-dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Plot from "@observablehq/plot";
import * as Arrow from "apache-arrow";
import * as d3 from "d3";

export async function arrowDates() {
const athletes = await d3.csv<any>("data/athletes.csv", d3.autoType);
const table = Arrow.tableFromJSON(athletes);
return Plot.rectY(table, Plot.binX(undefined, {x: "date_of_birth"})).plot();
}
1 change: 1 addition & 0 deletions test/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from "./anscombe-quartet.js";
export * from "./arc.js";
export * from "./armadillo.js";
export * from "./arrow.js";
export * from "./arrow-dates.js";
export * from "./aspectRatio.js";
export * from "./athletes-bins-colors.js";
export * from "./athletes-birthdays.js";
Expand Down
52 changes: 26 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,10 @@
dependencies:
shiki "1.6.2"

"@swc/helpers@^0.5.2":
version "0.5.7"
resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.5.7.tgz#36c05f61b412abcff3616ecc8634623bcc7c9618"
integrity sha512-BVvNZhx362+l2tSwSuyEUV4h7+jk9raNdoTSdLfwTshXJSaGmYKluGRJznziCI3KX02Z19DdsQrdfrpXAU3Hfg==
"@swc/helpers@^0.5.10":
version "0.5.11"
resolved "https://registry.yarnpkg.com/@swc/helpers/-/helpers-0.5.11.tgz#5bab8c660a6e23c13b2d23fcd1ee44a2db1b0cb7"
integrity sha512-YNlnKRWF2sVojTpIyzwou9XoTNbzbzONwRhOoniEioF1AtaitTvVZblaQRrAzChWQ1bLYyYSWzM18y4WwgzJ+A==
dependencies:
tslib "^2.4.0"

Expand All @@ -642,12 +642,12 @@
mkdirp "^3.0.1"
path-browserify "^1.0.1"

"@types/command-line-args@^5.2.1":
"@types/command-line-args@^5.2.3":
version "5.2.3"
resolved "https://registry.yarnpkg.com/@types/command-line-args/-/command-line-args-5.2.3.tgz#553ce2fd5acf160b448d307649b38ffc60d39639"
integrity sha512-uv0aG6R0Y8WHZLTamZwtfsDLVRnOa+n+n5rEvFWL5Na5gZ8V2Teab/duDPFzIIIhs9qizDpcavCusCLJZu62Kw==

"@types/command-line-usage@^5.0.2":
"@types/command-line-usage@^5.0.4":
version "5.0.4"
resolved "https://registry.yarnpkg.com/@types/command-line-usage/-/command-line-usage-5.0.4.tgz#374e4c62d78fbc5a670a0f36da10235af879a0d5"
integrity sha512-BwR5KP3Es/CSht0xqBcUXS3qCAUVXwpRKsV2+arxeb65atasuXG9LykC9Ab10Cw3s2raH92ZqOeILaQbsB2ACg==
Expand Down Expand Up @@ -900,20 +900,20 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.6.tgz#818551d39113081048bdddbef96701b4e8bb9d1b"
integrity sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==

"@types/node@^20.12.7":
version "20.14.9"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.9.tgz#12e8e765ab27f8c421a1820c99f5f313a933b420"
integrity sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==
dependencies:
undici-types "~5.26.4"

"@types/node@^20.5.0":
version "20.14.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.0.tgz#49ceec7b34f8621470cff44677fa9d461a477f17"
integrity sha512-5cHBxFGJx6L4s56Bubp4fglrEpmyJypsqI6RgzMfBHWUJQGWAAi8cWcgetEbZXHYXo9C2Fa4EEds/uSyS4cxmA==
dependencies:
undici-types "~5.26.4"

"@types/node@^20.6.0":
version "20.11.30"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.30.tgz#9c33467fc23167a347e73834f788f4b9f399d66f"
integrity sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==
dependencies:
undici-types "~5.26.4"

"@types/resolve@1.20.2":
version "1.20.2"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
Expand Down Expand Up @@ -1250,18 +1250,18 @@ anymatch@~3.1.2:
normalize-path "^3.0.0"
picomatch "^2.0.4"

apache-arrow@^15.0.2:
version "15.0.2"
resolved "https://registry.yarnpkg.com/apache-arrow/-/apache-arrow-15.0.2.tgz#d87c6447d64d6fab34aa70119362680b6617ce63"
integrity sha512-RvwlFxLRpO405PLGffx4N2PYLiF7FD86Q1hHl6J2XCWiq+tTCzpb9ngFw0apFDcXZBMpCzMuwAvA7hjyL1/73A==
apache-arrow@^16.0.2:
version "16.1.0"
resolved "https://registry.yarnpkg.com/apache-arrow/-/apache-arrow-16.1.0.tgz#7aa8d0d436dd0995d9dc5c36febf380d5b207209"
integrity sha512-G6GiM6tzPDdGnKUnVkvVr1Nt5+hUaCMBISiasMSiJwI5L5GKDv5Du7Avc2kxlFfB/LEK2LTqh2GKSxutMdf8vQ==
dependencies:
"@swc/helpers" "^0.5.2"
"@types/command-line-args" "^5.2.1"
"@types/command-line-usage" "^5.0.2"
"@types/node" "^20.6.0"
"@swc/helpers" "^0.5.10"
"@types/command-line-args" "^5.2.3"
"@types/command-line-usage" "^5.0.4"
"@types/node" "^20.12.7"
command-line-args "^5.2.1"
command-line-usage "^7.0.1"
flatbuffers "^23.5.26"
flatbuffers "^24.3.25"
json-bignum "^0.0.3"
tslib "^2.6.2"

Expand Down Expand Up @@ -2150,10 +2150,10 @@ flat@^5.0.2:
resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241"
integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==

flatbuffers@^23.5.26:
version "23.5.26"
resolved "https://registry.yarnpkg.com/flatbuffers/-/flatbuffers-23.5.26.tgz#01358e272a61239f0faf3bfbe4e014f3ace9d746"
integrity sha512-vE+SI9vrJDwi1oETtTIFldC/o9GsVKRM+s6EL0nQgxXlYV1Vc4Tk30hj4xGICftInKQKj1F3up2n8UbIVobISQ==
flatbuffers@^24.3.25:
version "24.3.25"
resolved "https://registry.yarnpkg.com/flatbuffers/-/flatbuffers-24.3.25.tgz#e2f92259ba8aa53acd0af7844afb7c7eb95e7089"
integrity sha512-3HDgPbgiwWMI9zVB7VYBHaMrbOO7Gm0v+yD2FV/sCKj+9NDeVL7BOBYUuhWAQGKWOzBo8S9WdMvV0eixO233XQ==

flatted@^3.2.9:
version "3.3.1"
Expand Down

0 comments on commit 1f5ded9

Please sign in to comment.