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

Error when loading complex NaN's #860

Closed
DavidWellnitz opened this issue Jul 30, 2021 · 4 comments · Fixed by JuliaData/Parsers.jl#86
Closed

Error when loading complex NaN's #860

DavidWellnitz opened this issue Jul 30, 2021 · 4 comments · Fixed by JuliaData/Parsers.jl#86

Comments

@DavidWellnitz
Copy link

DavidWellnitz commented Jul 30, 2021

I have a CSV File which contains complex values and some values are NaN + NaN*im, which throws an error when I try to read it with type fixed to ComplexF64. The underlying problem seems to be that parse(ComplexF64, "NaN + NaN*im") throws the error: ERROR: ArgumentError: cannot parse " NaN*" as Float64. I tried to "solve" this by setting strict=false like:
df = CSV.File(fname, header=header, type=ComplexF64, strict=false) |> DataFrame
where fname is the location of my file and header is the header, but it throws the same error.

Am I using strict wrong? And is the behavior of parse intentional?

@DavidWellnitz
Copy link
Author

Update: Using missingstring= "NaN+NaN*im" instead of strict=false works, but it still feels like strict=false should also work.

@quinnj
Copy link
Member

quinnj commented Aug 1, 2021

Hmmm, yes, an interesting problem. For non-standard types, we currently rely on calling Base.parse, but on invalid values, that may throw an error that we're currently not catching. We should probably switch to using Base.tryparse, so that strict=false works as you mentioned. We could also consider adding parsing support in Parsers.jl for Complex types, which would make parsing them much faster.

quinnj added a commit to JuliaData/Parsers.jl that referenced this issue Aug 1, 2021
Should fix JuliaData/CSV.jl#860. (probably
should backport this to 1.X branch).
quinnj added a commit to JuliaData/Parsers.jl that referenced this issue Aug 3, 2021
* Fix case where fallback Base.parse throws error

Should fix JuliaData/CSV.jl#860. (probably
should backport this to 1.X branch).
quinnj added a commit to JuliaData/Parsers.jl that referenced this issue Aug 3, 2021
* Fix case where fallback Base.parse throws error

Should fix JuliaData/CSV.jl#860. (probably
should backport this to 1.X branch).
@quinnj
Copy link
Member

quinnj commented Aug 3, 2021

Ok, this was fixed in JuliaData/Parsers.jl#86

@DavidWellnitz
Copy link
Author

Thanks :)

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

Successfully merging a pull request may close this issue.

2 participants