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: possibility to treat 0/1 column as number #1417

Open
kirsar opened this issue Dec 8, 2021 · 3 comments
Open

Csv: possibility to treat 0/1 column as number #1417

kirsar opened this issue Dec 8, 2021 · 3 comments

Comments

@kirsar
Copy link

kirsar commented Dec 8, 2021

Is there any way to override default csv type inference behavior
"Columns with only 0, 1, Yes, No, True, or False will be set to bool"
(or may be inject a callback somewhere)
and treat 0/1 column as number for random csv (no shema known upfront)?
Thanks.

https://fsprojects.github.io/FSharp.Data/library/CsvProvider.html#Controlling-the-column-types

@nhirschey
Copy link
Contributor

In general, I don't think so. But

  1. If the column name is known (e.g., MyColumn) you could specify that the column with that name is integer
type Csv =
  CsvProvider<"file.csv",
              Schema="MyColumn=int",
              ResolutionFolder=ResolutionFolder>
  1. You could use the csv parser instead to bypass auto conversion https://fsprojects.github.io/FSharp.Data/library/CsvFile.html

@certara-ksorokin
Copy link

@nhirschey thanks! Unfortunately my content is totally dynamic, no suggestions can be done upfront
So I introduced some post processing: if type inferred as boolean but column has only '0' and '1' cells, I forcely set it's type to integer.

@dsyme
Copy link
Contributor

dsyme commented Mar 11, 2024

I guess we should interpet this as a request for a feature request for a new static parameter StrictBooleans to the CsvProvider so that the provider only infers a boolean type for samples containing precisely true/false values

Currently the spec says: "Columns with only 0, 1, Yes, No, True, or False will be set to bool." With this static parameter this would become "Columns with only 0, 1, Yes, No, True, or False will be set to bool. If StrictBooleans is active, then columns with only true or false will be set to bool."

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

4 participants