Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive callback argument empty in typescript #268

Open
msonnabaum opened this issue Feb 16, 2022 · 1 comment
Open

Derive callback argument empty in typescript #268

msonnabaum opened this issue Feb 16, 2022 · 1 comment

Comments

@msonnabaum
Copy link

I'm running into a strange issue where if I import the library in typescript and use the derive method, the callback argument is undefined:

import * as aq from "arquero";

const data = {
  a: [1, 3, 5, 7],
  b: [2, 4, 6, 8],
};

const dt = aq.table(data).derive({ c: d => d?.a + d?.b });
ReferenceError: d is not defined
    at eval (eval at compile (/arquero-test/node_modules/arquero/dist/arquero.node.js:3848:11), <anonymous>:3:98)
    at output$2 (/arquero-test/node_modules/arquero/dist/arquero.node.js:8660:18)
    at _derive (/arquero-test/node_modules/arquero/dist/arquero.node.js:8619:7)
    at ColumnTable.__derive (/arquero-test/node_modules/arquero/dist/arquero.node.js:8667:14)
    at ColumnTable.derive (/arquero-test/node_modules/arquero/dist/arquero.node.js:121:17)
    at Object.<anonymous> (/arquero-test/index.ts:8:27)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Module.m._compile (/arquero-test/node_modules/ts-node/src/index.ts:1459:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
    at Object.require.extensions.<computed> [as .ts] (/arquero-test/node_modules/ts-node/src/index.ts:1462:12)

This seems like it might be related to how it's imported, because if I use vanilla javascript and import using const arquero = require("arquero"), it works as expected.

I setup a minimal repository that reproduces the issue: https://github.com/msonnabaum/arquero-test

If you npm install and then npx ts-node index.ts you should get the error referenced above.

@RichardCzechowski
Copy link

RichardCzechowski commented Sep 21, 2022

I ran into this as well. What I discovered is, in this case, it ignores or fails to parse the parameter names you provide and instead calls it like this:
(row,data,op)=> { \\ your expression}
So you can access row internally to the same effect as the d in the examples.

The other thing I had some success with was escaping (aq.escape) the function I was calling to keep the compiler from renaming my variables. I was trying to use a param to pass data into my function so I could access it with data.foo but my data variable was always renamed to data4 or some similar thing. Escaping the function kept my variable names as I had named them.

Code in question
https://github.com/uwdata/arquero/blob/main/src/expression/compile.js#L10

Where to throw a debugger to see it in action
https://github.com/uwdata/arquero/blob/main/src/expression/compile.js#L4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants