Skip to content

Commit 1f5ded9

Browse files
committed
fix apache arrow dates (alternative to #2096)
1 parent 932186c commit 1f5ded9

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"@types/node": "^20.5.0",
5757
"@typescript-eslint/eslint-plugin": "^7.2.0",
5858
"@typescript-eslint/parser": "^7.2.0",
59-
"apache-arrow": "^15.0.2",
59+
"apache-arrow": "^16.0.2",
6060
"c8": "^9.1.0",
6161
"canvas": "^2.0.0",
6262
"d3-geo-projection": "^4.0.0",

src/options.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,13 @@ function isArrowTable(data) {
584584

585585
// Extract columnar data
586586
function columnar(data, name, type) {
587-
return isArrowTable(data) ? maybeTypedArrayify(data.getChild(name), type) : maybeTypedMap(data, field(name), type);
587+
if (isArrowTable(data)) {
588+
const column = maybeTypedArrayify(data.getChild(name), type);
589+
if (Array.isArray(column) && String(data.schema?.fields?.find((d) => d.name === name)).endsWith("<MILLISECOND>"))
590+
column.find((d, i) => d != null && (column[i] = new Date(d)));
591+
return column;
592+
}
593+
return maybeTypedMap(data, field(name), type);
588594
}
589595

590596
// Arrayify arrow tables. We try to avoid materializing the values, but the

test/plots/arrow-dates.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as Arrow from "apache-arrow";
3+
import * as d3 from "d3";
4+
5+
export async function arrowDates() {
6+
const athletes = await d3.csv<any>("data/athletes.csv", d3.autoType);
7+
const table = Arrow.tableFromJSON(athletes);
8+
return Plot.rectY(table, Plot.binX(undefined, {x: "date_of_birth"})).plot();
9+
}

test/plots/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * from "./anscombe-quartet.js";
1212
export * from "./arc.js";
1313
export * from "./armadillo.js";
1414
export * from "./arrow.js";
15+
export * from "./arrow-dates.js";
1516
export * from "./aspectRatio.js";
1617
export * from "./athletes-bins-colors.js";
1718
export * from "./athletes-birthdays.js";

yarn.lock

+26-26
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,10 @@
625625
dependencies:
626626
shiki "1.6.2"
627627

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

@@ -642,12 +642,12 @@
642642
mkdirp "^3.0.1"
643643
path-browserify "^1.0.1"
644644

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

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

903+
"@types/node@^20.12.7":
904+
version "20.14.9"
905+
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.9.tgz#12e8e765ab27f8c421a1820c99f5f313a933b420"
906+
integrity sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==
907+
dependencies:
908+
undici-types "~5.26.4"
909+
903910
"@types/node@^20.5.0":
904911
version "20.14.0"
905912
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.0.tgz#49ceec7b34f8621470cff44677fa9d461a477f17"
906913
integrity sha512-5cHBxFGJx6L4s56Bubp4fglrEpmyJypsqI6RgzMfBHWUJQGWAAi8cWcgetEbZXHYXo9C2Fa4EEds/uSyS4cxmA==
907914
dependencies:
908915
undici-types "~5.26.4"
909916

910-
"@types/node@^20.6.0":
911-
version "20.11.30"
912-
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.30.tgz#9c33467fc23167a347e73834f788f4b9f399d66f"
913-
integrity sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==
914-
dependencies:
915-
undici-types "~5.26.4"
916-
917917
918918
version "1.20.2"
919919
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
@@ -1250,18 +1250,18 @@ anymatch@~3.1.2:
12501250
normalize-path "^3.0.0"
12511251
picomatch "^2.0.4"
12521252

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

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

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

21582158
flatted@^3.2.9:
21592159
version "3.3.1"

0 commit comments

Comments
 (0)