Skip to content

Commit 92e3e32

Browse files
committed
fix apache arrow dates (alternative to #2096)
1 parent f3fc61b commit 92e3e32

File tree

5 files changed

+44
-28
lines changed

5 files changed

+44
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"@types/node": "^20.5.0",
5858
"@typescript-eslint/eslint-plugin": "^7.2.0",
5959
"@typescript-eslint/parser": "^7.2.0",
60-
"apache-arrow": "^15.0.2",
60+
"apache-arrow": "^16.0.2",
6161
"c8": "^9.1.0",
6262
"canvas": "^2.0.0",
6363
"d3-geo-projection": "^4.0.0",

src/options.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,13 @@ function isArrowTable(data) {
568568

569569
// Extract columnar data
570570
function columnar(data, name, type) {
571-
return isArrowTable(data) ? maybeTypedArrayify(data.getChild(name), type) : maybeTypedMap(data, field(name), type);
571+
if (isArrowTable(data)) {
572+
const column = maybeTypedArrayify(data.getChild(name), type);
573+
if (Array.isArray(column) && String(data.schema?.fields?.find((d) => d.name === name)).endsWith("<MILLISECOND>"))
574+
column.find((d, i) => d != null && (column[i] = new Date(d)));
575+
return column;
576+
}
577+
return maybeTypedMap(data, field(name), type);
572578
}
573579

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

test/plots/arrow-dates.ts

Lines changed: 9 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -598,10 +598,10 @@
598598
dependencies:
599599
shiki "1.1.7"
600600

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

@@ -615,12 +615,12 @@
615615
mkdirp "^3.0.1"
616616
path-browserify "^1.0.1"
617617

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

623-
"@types/command-line-usage@^5.0.2":
623+
"@types/command-line-usage@^5.0.4":
624624
version "5.0.4"
625625
resolved "https://registry.yarnpkg.com/@types/command-line-usage/-/command-line-usage-5.0.4.tgz#374e4c62d78fbc5a670a0f36da10235af879a0d5"
626626
integrity sha512-BwR5KP3Es/CSht0xqBcUXS3qCAUVXwpRKsV2+arxeb65atasuXG9LykC9Ab10Cw3s2raH92ZqOeILaQbsB2ACg==
@@ -878,20 +878,20 @@
878878
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-10.0.6.tgz#818551d39113081048bdddbef96701b4e8bb9d1b"
879879
integrity sha512-dJvrYWxP/UcXm36Qn36fxhUKu8A/xMRXVT2cliFF1Z7UA9liG5Psj3ezNSZw+5puH2czDXRLcXQxf8JbJt0ejg==
880880

881+
"@types/node@^20.12.7":
882+
version "20.14.9"
883+
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.9.tgz#12e8e765ab27f8c421a1820c99f5f313a933b420"
884+
integrity sha512-06OCtnTXtWOZBJlRApleWndH4JsRVs1pDCc8dLSQp+7PpUpX3ePdHyeNSFTeSe7FtKyQkrlPvHwJOW3SLd8Oyg==
885+
dependencies:
886+
undici-types "~5.26.4"
887+
881888
"@types/node@^20.5.0":
882889
version "20.11.26"
883890
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.26.tgz#3fbda536e51d5c79281e1d9657dcb0131baabd2d"
884891
integrity sha512-YwOMmyhNnAWijOBQweOJnQPl068Oqd4K3OFbTc6AHJwzweUwwWG3GIFY74OKks2PJUDkQPeddOQES9mLn1CTEQ==
885892
dependencies:
886893
undici-types "~5.26.4"
887894

888-
"@types/node@^20.6.0":
889-
version "20.11.30"
890-
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.30.tgz#9c33467fc23167a347e73834f788f4b9f399d66f"
891-
integrity sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==
892-
dependencies:
893-
undici-types "~5.26.4"
894-
895895
"@types/resolve@1.20.2":
896896
version "1.20.2"
897897
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-1.20.2.tgz#97d26e00cd4a0423b4af620abecf3e6f442b7975"
@@ -1237,18 +1237,18 @@ anymatch@~3.1.2:
12371237
normalize-path "^3.0.0"
12381238
picomatch "^2.0.4"
12391239

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

@@ -2130,10 +2130,10 @@ flat@^5.0.2:
21302130
resolved "https://registry.yarnpkg.com/flat/-/flat-5.0.2.tgz#8ca6fe332069ffa9d324c327198c598259ceb241"
21312131
integrity sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==
21322132

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

21382138
flatted@^3.2.9:
21392139
version "3.3.1"

0 commit comments

Comments
 (0)