Error while executing code with function node

I am facing an issue using a third-party library "danfojs-node" with a function node.

I am running this snippet with node.js and it produces the expected result.

const dfd = require("danfojs-node");
json_data = [
    { A: 0.4612, B: 4.28283, C: -1.509, D: -1.1352 },
    { A: 0.5112, B: -0.22863, C: -3.39059, D: 1.1632 },
    { A: 0.6911, B: -0.82863, C: -1.5059, D: 2.1352 },
    { A: 0.4692, B: -1.28863, C: 4.5059, D: 4.1632 },
df = new dfd.DataFrame(json_data);

Result is:

║   │ A                 │ B                 │ C                 │ D                 ║
║ 0 │ 0.4612            │ 4.28283           │ -1.509            │ -1.1352           ║
║ 1 │ 0.5112            │ -0.22863          │ -3.39059          │ 1.1632            ║
║ 2 │ 0.6911            │ -0.82863          │ -1.5059           │ 2.1352            ║
║ 3 │ 0.4692            │ -1.28863          │ 4.5059            │ 4.1632            ║

When I run the same code with the node-red function node, it gives me an error. (See the attached files)
"Error: File format not supported"

Node-RED version: 1.3.3
Node.js version: v12.16.1
The latest version of danfojs-node (0.2.6) has been used in both cases.

Screenshot from 2021-05-27 15-29-17

Is this not the same issue as this? : Wrong exception thrown for empty dataframe · Issue #37 · opensource9ja/danfojs · GitHub

I further inspected the source code of "danfojs-node" and found that

is object check is passing when I am running the above code snippet with node.js and it fails when I execute the code with node-red function.

Source code:
The code where its checking for isObject is here:

return value && typeof value === "object" && value.constructor === Object;

The above util function gets called when we create new dataframe (df = new dfd.DataFrame(json_data); )

To be specific This check is failing when executing code with node-red function
value.constructor === Object

If you have any ideas why its behaving this way, please let me know.

I believe it's not the same. The code snippet (i attached above) is working fine when directly executing with the node.js. it's only throwing the error when code is being executed by node-red function.

This is likely due to the way the function node runs it's code inside the VM modules - that can have odd side effects in code that tries to do certain types of comparison between an object created inside the VM and one created outside.

If that is the case, there isn't a short term solution I can give you - it's a consequence of how the node works.

I was heading to the same conclusion & now you say it, I believe that is the issue.

@vinaysudani I tried it in nodejs and a function node and see the same issue you do.

As a workaround, I changed the __is_object function to return value && typeof value === "object" && value.constructor && === "Object" & it works in the function node vm.

Maybe you could raise an issue against the repo stating it doesn't work as expected in a nodejs vm?

Thanks, @knolleary @Steve-Mcl for your quick replies.

I will report an issue on "danfojs-node" to look into this senario.

This issue is now resolved by the merge of this pull request: Fixes #206 Testing if value is an object by risenW · Pull Request #208 · opensource9ja/danfojs · GitHub

Thanks, everyone for your participation in resolving the issue.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.