pola-rs / nodejs-polars

nodejs front-end of polars
https://pola-rs.github.io/nodejs-polars/
MIT License
393 stars 40 forks source link

Code from `pivot` documentation example trows error: Given napi value is not an array #272

Open paladinic opened 5 hours ago

paladinic commented 5 hours ago

Have you tried latest version of polars?

What version of polars are you using?

"nodejs-polars": "^0.15.0",

What operating system are you using polars on?

Windows 11

What node version are you using

Node.js v18.18.0

Describe your bug.

Give a high level description of the bug.

What are the steps to reproduce the behavior?

Please use code instead of images, we don't like typing.

If the example is large, put it in a gist: https://gist.github.com/

If the example is small, put it in code fences:

const pl = require('nodejs-polars');

const dx = pl.DataFrame(
        {
            "foo": ["one", "one", "one", "two", "two", "two"],
            "bar": ["A", "B", "C", "A", "B", "C"],
            "baz": [1, 2, 3, 4, 5, 6],
        }
    );

dx.pivot("baz", {index:"foo", columns:"bar"});

What is the actual behavior?

Running the df.pivot example throws the error below:

 ...\node_modules\nodejs-polars\bin\dataframe.js:361
              return (0, exports._DataFrame)(_df.pivotExpr(values, on, index, fn, maintainOrder, sortColumns, separator));
                                                 ^
  Error: Given napi value is not an array
     at Proxy.pivot (C:\...\node_modules\nodejs-polars\bin\dataframe.js:361:48)
    at Object.<anonymous> (C:\....\app.js)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:86:12)
    at node:internal/main/run_main_module:23:47 {
  code: 'InvalidArg'
}

Node.js v18.18.0

What is the expected behavior?

The same output of the example here: https://pola-rs.github.io/nodejs-polars/interfaces/pl.DataFrame-1.html#pivot.pivot-1

  shape: (2, 4)
  ┌─────┬─────┬─────┬─────┐
  │ foo ┆ A   ┆ B   ┆ C   │
  │ --- ┆ --- ┆ --- ┆ --- │
  │ str ┆ f64 ┆ f64 ┆ f64 │
  ╞═════╪═════╪═════╪═════╡
  │ one ┆ 1   ┆ 2   ┆ 3   │
  ├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
  │ two ┆ 4   ┆ 5   ┆ 6   │
  └─────┴─────┴─────┴─────┘
paladinic commented 4 hours ago

I just tried:

But I still get the error.