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

Unable to parse Date #113

Open
pazzo83 opened this issue Feb 12, 2019 · 3 comments
Open

Unable to parse Date #113

pazzo83 opened this issue Feb 12, 2019 · 3 comments

Comments

@pazzo83
Copy link

pazzo83 commented Feb 12, 2019

I am trying to parse a simple CSV which looks like this:

"007018","99999","WXPOD 7018","","","","+00.000","+000.000","+7018.0","20110309","20130730"
"007026","99999","WXPOD 7026","AF","","","+00.000","+000.000","+7026.0","20120713","20170822"
"007070","99999","WXPOD 7070","AF","","","+00.000","+000.000","+7070.0","20140923","20150926"
"008260","99999","WXPOD8270","","","","+00.000","+000.000","+0000.0","19960101","20100731"
"008268","99999","WXPOD8278","AF","","","+32.950","+065.567","+1156.7","20100519","20120323"
"008307","99999","WXPOD 8318","AF","","","+00.000","+000.000","+8318.0","20100421","20100421"
"008411","99999","XM20","","","","","","","20160217","20160217"
"008414","99999","XM18","","","","","","","20160216","20160217"
"008415","99999","XM21","","","","","","","20160217","20160217"
"008418","99999","XM24","","","","","","","20160217","20160217"

and I am trying to parse the last two columns as dates (dateformat"yyyymmdd")

I believe this is the correct way to set up the colparser for the load:

loadtable(
  "/Users/christopheralexander/Documents/testcsv.csv", 
  colparsers=Dict(10=> dateformat"yyyymmdd"), 
  colnames=["usaf", "wban", "name", "ccode", "state", "icao", "lat", "lon", "elev", "startdate", "enddate"],
  header_exists=false, indexcols=[1, 2]
)

...however I am getting the following exception:

ERROR: MethodError: no method matching length(::TextParse.StrRange)
Closest candidates are:
  length(::Core.SimpleVector) at essentials.jl:561
  length(::Base.MethodList) at reflection.jl:801
  length(::Core.MethodTable) at reflection.jl:875
  ...
_similar_for(::UnitRange{Int64}, ::Type{Any}, ::TextParse.StrRange, ::Base.HasLength) at ./array.jl:517
_collect(::UnitRange{Int64}, ::TextParse.StrRange, ::Base.HasEltype, ::Base.HasLength) at ./array.jl:550
collect(::TextParse.StrRange) at ./array.jl:544
broadcastable(::TextParse.StrRange) at ./broadcast.jl:614
broadcasted at ./broadcast.jl:1159 [inlined]

Is the syntax I am using wrong?

@davidanthoff
Copy link
Member

I think you are starting this from JuliaDB, right? Could you try whether it works if you stick with just TextParse.jl? Like this:

using TextParse

csvread(
  "/Users/christopheralexander/Documents/testcsv.csv", 
  colparsers=Dict(10=> dateformat"yyyymmdd"), 
  colnames=["usaf", "wban", "name", "ccode", "state", "icao", "lat", "lon", "elev", "startdate", "enddate"],
  header_exists=false
)

And for the error, is there more output, i.e. more of a stack trace? It is difficult to tell where things go wrong from just the stack trace that you posted.

@pazzo83
Copy link
Author

pazzo83 commented Feb 19, 2019

Gonna resolve this, but you can consider whether it is actually a bug or not. I had to pass to colparsers this: 10 => dateformat"\"yyyymmdd\"" because I guess the date was literally enclosed in quotes.

@pazzo83 pazzo83 closed this as completed Feb 19, 2019
@davidanthoff
Copy link
Member

Lets leave it open for now, there is probably a way that we could improve this.

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

No branches or pull requests

2 participants