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

toRecords should support empty header fields #254

Open
ad-si opened this issue Aug 22, 2024 · 2 comments
Open

toRecords should support empty header fields #254

ad-si opened this issue Aug 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@ad-si
Copy link

ad-si commented Aug 22, 2024

Have you tried latest version of polars?

  • [yes]

What version of polars are you using?

0.14

What operating system are you using polars on?

macOS 14.6.1

What node version are you using

bun 1.1.21

Describe your bug

Using toRecords() on a dataframe with an empty header cell should work, but currently it throws an Error.

What are the steps to reproduce the behavior?

import pl from "nodejs-polars"

const csv =`"name",""
"John","green"
"Anna","red"
`
pl.readCSV(csv, { quoteChar: "\"" }).toRecords()
474 |             _df.writeCsv(writeStream, dest ?? options);
475 |             writeStream.end("");
476 |             return Buffer.concat(buffers);
477 |         },
478 |         toRecords() {
479 |             return _df.toObjects();
                             ^
error: Failed to set property with field ``
 code: "InvalidArg"
@ad-si ad-si added the bug Something isn't working label Aug 22, 2024
@ad-si ad-si changed the title readCSV should support empty header fields toRecords should support empty header fields Aug 22, 2024
@ad-si
Copy link
Author

ad-si commented Aug 22, 2024

As a workaround you can add a .withColumnRenamed("", "__EMPTY")

Edit: No, you can't because it will throw an error if the column name does not exist. 😮‍💨
Use this instead:

if (df.columns.includes("")) {
  df = df.withColumnRenamed("", "__EMPTY")
}

@Bidek56
Copy link
Collaborator

Bidek56 commented Aug 29, 2024

It's strange b/c it works fine using Node v22.7.0 and in our tests, so I wonder if it's a Bun issue. Hmm
@universalmind303 what do you think? Thx

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

No branches or pull requests

2 participants