Skip to content

Commit 0bd5908

Browse files
authored
Add support for arquero (#25)
1 parent 888b1d2 commit 0bd5908

File tree

5 files changed

+215
-11
lines changed

5 files changed

+215
-11
lines changed

package-lock.json

Lines changed: 193 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@
389389
"@types/yargs": "^17.0.2",
390390
"@typescript-eslint/eslint-plugin": "^4.29.0",
391391
"@typescript-eslint/parser": "^4.29.0",
392+
"arquero": "^4.8.4",
392393
"cache-loader": "^4.1.0",
393394
"concurrently": "^5.2.0",
394395
"copy-webpack-plugin": "^9.0.0",

src/extension/server/codeExecution.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { register as registerTsNode } from './tsnode';
1414
import { noop } from '../coreUtils';
1515
import { createConsoleOutputCompletedMarker } from '../const';
1616
import { DanfoNodePlotter } from './extensions/danforPlotter';
17+
import { ArqueroFormatter } from './extensions/arqueroFormatter';
1718
// eslint-disable-next-line @typescript-eslint/no-var-requires
1819
const Module = require('module');
1920

@@ -153,9 +154,6 @@ async function runCode(
153154
}
154155
}
155156

156-
async function runCodeSilently(code: string | CodeObject): Promise<unknown> {
157-
return runCode(code, 'silent');
158-
}
159157
async function replEvalCode(code, _context, _filename, _callback) {
160158
return runCode(code);
161159
}
@@ -303,15 +301,14 @@ Module._load = function (request: any, parent: any) {
303301
});
304302
return TensorflowJsVisualizer.initialize(tfCore, tfMath);
305303
}
306-
if (request === '@tensorflow/tfjs-node') {
307-
// injectCustomProgress();
308-
// TensorFormatter.initialize();
309-
}
310304

311305
// eslint-disable-next-line prefer-rest-params
312306
const result = originalLoad.apply(this, arguments);
313307
if (request === 'danfojs-node') {
314-
DanfoJsFormatter.initialize(runCodeSilently, result);
308+
DanfoJsFormatter.initialize(result);
309+
}
310+
if (request === 'arquero') {
311+
ArqueroFormatter.initialize(result);
315312
}
316313
return result;
317314
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export class ArqueroFormatter {
2+
public static initialize(arquero: typeof import('arquero')) {
3+
var table = arquero.table({ colA: ['a', 'b', 'c'], colB: [3, 4, 5] });
4+
const proto = (table as any).__proto__ || (table as any).protptype;
5+
if (!proto) {
6+
return;
7+
}
8+
proto.print = function (opts) {
9+
const { display } = require('node-kernel');
10+
display.html(this.toHTML(opts));
11+
};
12+
}
13+
}

src/extension/server/extensions/danfoFormatter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export class DanfoJsFormatter {
2020
DanfoJsFormatter._instance = new DanfoJsFormatter();
2121
return DanfoJsFormatter._instance;
2222
}
23-
public static initialize(codeRunner: (code: string) => Promise<unknown>, danfoModule: typeof dfd) {
24-
DanfoJsFormatter.instance.inject(codeRunner, danfoModule);
23+
public static initialize(danfoModule: typeof dfd) {
24+
DanfoJsFormatter.instance.inject(danfoModule);
2525
}
2626
public canFormatAsDanfo(value: unknown) {
2727
if ((!value && typeof value !== 'object') || !this.danfoJs) {
@@ -68,7 +68,7 @@ export class DanfoJsFormatter {
6868
};
6969
}
7070
}
71-
public inject(codeRunner: (code: string) => Promise<unknown>, danfoModule: typeof dfd) {
71+
public inject(danfoModule: typeof dfd) {
7272
if (this.isLoaded || this.failedToInject) {
7373
return;
7474
}

0 commit comments

Comments
 (0)