mafintosh / mafintosh/csv-parser

is mapValues called on skipped lines?

Open
#222 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
1.5k
Forks
143
PR merge metrics
No merged PRs in 30d

Description

Documentation Is:

- [ ] Missing
- [ ] Needed
- [x] Confusing
- [ ] Not Sure?

### Please Explain in Detail...

I am a little unclear on whether the `mapValues` function is called for skipped lines.

I assumed that it would not be called for skipped lines, but when writing some tests it seems like the mapValues function is being called for a skipped line.

My test data:

```csv
t,u,v,w
a,101,1.02,2.02
b,101,1.03,2.03
```

My `csv-parser.Options` :

```javascript
opts: {
headers: [ 'id', 'timestamp', 'x', 'y' ],
skipLines: 1,
mapHeaders: [Function: mapHeaders],
mapValues: [Function: mapValues]
}
```

The error I see in my `mapValues` function when I run my tests.

```
Error during date parsing: {
filePath: '/xxx/tests/custom-headers.csv',
header: 'timestamp',
value: 'u',
index: 1,
opts: {
headers: [ 'id', 'timestamp', 'x', 'y' ],
skipLines: 1,
mapHeaders: [Function: mapHeaders],
mapValues: [Function: mapValues]
}
}
```

### Your Proposal for Changes

I think it's fair to assume that the `mapValues` function would skip the number of lines defined by the `skipLines` option.

If this is not the intent, and you don't agree that it's fair to assume that the `mapValues` function would not be run on skipped lines, then please close this ticket.

If it is the intent of the parser to skip these lines then either I am doing something wrong or there's a bug.

If the library was designed to run the `mapValues` function on skipped lines but you agree that it is a fair assumption that it shouldn't, then we should update the documentation to let users know that `mapValues` will be run on skipped lines.

Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reported behavior with the CSV data and the shown skipLines, headers, mapHeaders, and mapValues options. Trace how skipped rows reach mapValues, then establish whether the observed call is intended; done means the behavior is clarified and the issue's proposed documentation or bug resolution is supported by a regression check.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.