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

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

Closed
paladinic opened this issue Sep 21, 2024 · 2 comments · Fixed by #273
Closed
Labels
bug Something isn't working

Comments

@paladinic
Copy link

paladinic commented Sep 21, 2024

Have you tried latest version of polars?

  • [yes]

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 paladinic added the bug Something isn't working label Sep 21, 2024
@paladinic
Copy link
Author

I just tried:

  • updating node.js (v20.17.0)
  • restarting my machine
  • uninstalling and reinstalling nodejs-polars

But I still get the error.

@Bidek56
Copy link
Collaborator

Bidek56 commented Sep 21, 2024

Please use: df.pivot("baz", {index:"foo", on:"bar"});
I have pushed a PR to fixed the doc.
Thanks for catching this issue.

universalmind303 pushed a commit that referenced this issue Sep 23, 2024
Fixing pivot docs and example to close #272
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants