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

[csv] Parser failed when a cell doesn't have value #76

Open
namm2 opened this issue Aug 20, 2024 · 1 comment
Open

[csv] Parser failed when a cell doesn't have value #76

namm2 opened this issue Aug 20, 2024 · 1 comment

Comments

@namm2
Copy link
Contributor

namm2 commented Aug 20, 2024

HI, I'm trying to parse a csv file which was exported from spreadsheet, but the csv parser failed when a cell doesn't have any value:

import "package://pkg.pkl-lang.org/pkl-pantry/[email protected]#/csv.pkl"

data = """
  Column1, Column2, Column3, Column 4
  Value 1, Value 2,, Value 4
  """

csvData = new csv.Parser {
  input = data
  includeHeader = true
}.parsed

But got pkl error:

–– Pkl Error ––
Expected value of type `String`, but got `null`.

188 | let (header: List<String>? = (if (includeHeader) stringyResult[0] else properties?.keys)?.toList() as List<String>?)
                                                                                                                 ^^^^^^
at pkl.csv.csv#Parser._parsed.<function#3> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/pkl.csv/csv.pkl#L188-188)

187 | let (properties: Map<String,reflect.Property>? = rowClass.ifNonNull((clazz) -> allProps(reflect.Class(clazz as Class))))
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.csv.csv#Parser._parsed.<function#2> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/pkl.csv/csv.pkl#L187-203)

182 | let (stringyResult = new StringyTableParser {
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.csv.csv#Parser._parsed.<function#1> (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/pkl.csv/csv.pkl#L182-203)

181 | let (self = this)
      ^^^^^^^^^^^^^^^^^
at pkl.csv.csv#Parser._parsed (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/pkl.csv/csv.pkl#L181-203)

164 | _parsed
      ^^^^^^^
at pkl.csv.csv#Parser.parsed (https://github.com/apple/pkl-pantry/blob/[email protected]/packages/pkl.csv/csv.pkl#L164-164)

8 | csvData = new csv.Parser {
              ^^^^^^^^^^^^^^^^
at kv2#csvData (file:///Users/namnguyen/scripts/vault/kv2.pkl, line 8)

106 | text = renderer.renderDocument(value)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
at pkl.base#Module.output.text (https://github.com/apple/pkl/blob/0.26.3/stdlib/base.pkl#L106)

Coming from python's csv (I know it's apple to orange comparison, but anyway), I don't expect this error.

@holzensp
Copy link
Contributor

I can reproduce and agree this is surprising and undesirable behaviour. Thanks for filing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants