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

skipRows does not skip rows for readCSV when CSVs have new lines #299

Open
mbornstein opened this issue Nov 29, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@mbornstein
Copy link

Have you tried latest version of polars?

  • yes

What version of polars are you using?

0.16.0

What operating system are you using polars on?

Mac OS 15.1 (24B83)

What node version are you using

using Bun v 1.1.37

Describe your bug.

Give a high level description of the bug.

What are the steps to reproduce the behavior?

here is a test

it("repro ", () => {
  const df = pl.readCSV(
    dedent`
    "name
    a","height
    b"
    "John",172.23
    "Anna",1653.34
  `,
    { quoteChar: "\"", sep: ",", hasHeader: false, skipRows: 1 },
  )
  expect(df.toRecords()).toEqual([
    { "column_1": "John", "column_2": 172.23 },
    { "column_1": "Anna", "column_2": 1653.34 },
  ])
})

produces:

60 |     "John",172.23
61 |     "Anna",1653.34
62 |   `,
63 |     { quoteChar: "\"", sep: ",", hasHeader: false, skipRows: 1 },
64 |   )
65 |   expect(df.toRecords()).toEqual([
                              ^
error: expect(received).toEqual(expected)

  [
    {
+     column_1: "a\"",
+     column_2: null,
+   },
+   {
      column_1: "John",
      column_2: 172.23,
    },
    {
      column_1: "Anna",
      column_2: 1653.34,
    }
  ]

- Expected  - 0
+ Received  + 4

What is the actual behavior?

it seems the quote character is not respected and skipRows only looks for \n

What is the expected behavior?

the first line should be "name\na,height\nb" and the second row should start with "John"..

skipRows should respect the quoting character and skip actual rows and not lines

@mbornstein mbornstein added the bug Something isn't working label Nov 29, 2024
@Bidek56
Copy link
Collaborator

Bidek56 commented Dec 1, 2024

Using: skipRowsAfterHeader: 3 passes the test in Bun

it("repro ", () => {
    const df = pl.readCSV(
      dedent`
      "name
      a","height
      b"
      "John",172.23
      "Anna",1653.34
    `,
      { quoteChar: '"', sep: ",", hasHeader: false, skipRowsAfterHeader: 3 },
    )
    expect(df.toRecords()).toEqual([
      { "column_1": "John", "column_2": "172.23" },
      { "column_1": "Anna", "column_2": "1653.34" },
    ])
  })

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