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

UndefVarError: writeshortest not defined on CSV.write #1056

Closed
anandijain opened this issue Dec 1, 2022 · 5 comments
Closed

UndefVarError: writeshortest not defined on CSV.write #1056

anandijain opened this issue Dec 1, 2022 · 5 comments

Comments

@anandijain
Copy link

https://discourse.julialang.org/t/csv-write-writeshortest-error/90336

@mbauman
Copy link

mbauman commented Dec 1, 2022

This is specific to some old versions of CSV.jl (e.g., v0.9.11); it's trying to use Parsers.writeshortest which is not defined in the version of Parsers that gets installed with that version of CSV.jl (v2.5.1).

MWE by Seb-MC on Discourse
(@v1.8) pkg> activate --temp
...
(jl_cOmpJF) pkg> add CSV@v0.9.11
...
(jl_cOmpJF) pkg> add DataFrames
...
julia> using DataFrames, CSV
julia> cd(mktempdir())

julia> df = DataFrame(:a=>rand(3))
3×1 DataFrame
 Row │ a
     │ Float64
─────┼──────────
   10.100739
   20.346434
   30.657864

julia> CSV.write("a.csv", df)
ERROR: UndefVarError: writeshortest not defined
Stacktrace:
  [1] writecell(buf::Vector{UInt8}, pos::Int64, len::Int64, io::IOStream, x::Float64, opts::CSV.Options{UInt8, UInt8, Nothing, Tuple{}, typeof(CSV._identity)})
    @ CSV C:\Users\sebastian\.julia\packages\CSV\9LsxT\src\write.jl:444
  [2] (::CSV.var"#112#113"{Vector{UInt8}, Base.RefValue{Int64}, Int64, IOStream, Int64, CSV.Options{UInt8, UInt8, Nothing, Tuple{}, typeof(CSV._identity)}, UInt8, UInt8})(val::Float64, col::Int64, nm::Symbol)
    @ CSV C:\Users\sebastian\.julia\packages\CSV\9LsxT\src\write.jl:371
  [3] eachcolumn
    @ C:\Users\sebastian\.julia\packages\Tables\T7rHm\src\utils.jl:70 [inlined]
  [4] writerow(buf::Vector{UInt8}, pos::Base.RefValue{Int64}, len::Int64, io::IOStream, sch::Tables.Schema{(:a,), Tuple{Float64}}, row::DataFrameRow{DataFrame, DataFrames.Index}, cols::Int64, opts::CSV.Options{UInt8, UInt8, Nothing, Tuple{}, typeof(CSV._identity)})
    @ CSV C:\Users\sebastian\.julia\packages\CSV\9LsxT\src\write.jl:367
  [5] (::CSV.var"#105#106"{Bool, Bool, Tables.Schema{(:a,), Tuple{Float64}}, DataFrames.DataFrameRows{DataFrame}, CSV.Options{UInt8, UInt8, Nothing, Tuple{}, typeof(CSV._identity)}, Vector{UInt8}, Int64, Int64, Tuple{Symbol}})(io::IOStream)
    @ CSV C:\Users\sebastian\.julia\packages\CSV\9LsxT\src\write.jl:235
  [6] with(f::CSV.var"#105#106"{Bool, Bool, Tables.Schema{(:a,), Tuple{Float64}}, DataFrames.DataFrameRows{DataFrame}, CSV.Options{UInt8, UInt8, Nothing, Tuple{}, typeof(CSV._identity)}, Vector{UInt8}, Int64, Int64, Tuple{Symbol}}, io::Any,
 append::Bool, compress::Bool)
    @ CSV C:\Users\sebastian\.julia\packages\CSV\9LsxT\src\write.jl:303
  [7] #write#104
    @ C:\Users\sebastian\.julia\packages\CSV\9LsxT\src\write.jl:225 [inlined]
  [8] write(file::String, itr::DataFrame; delim::Char, quotechar::Char, openquotechar::Nothing, closequotechar::Nothing, escapechar::Char, newline::Char, decimal::Char, dateformat::Nothing, quotestrings::Bool, missingstring::String, transform::typeof(CSV._identity), bom::Bool, append::Bool, compress::Bool, writeheader::Nothing, partition::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ CSV C:\Users\sebastian\.julia\packages\CSV\9LsxT\src\write.jl:210
  [9] write(file::String, itr::DataFrame)
    @ CSV C:\Users\sebastian\.julia\packages\CSV\9LsxT\src\write.jl:153
 [10] top-level scope
    @ REPL[9]:1

A quick and dirty hotpatch is to do an:

@eval CSV.Parsers import Base.Ryu: writeshortest

@quinnj
Copy link
Member

quinnj commented Dec 1, 2022

@mbauman is correct; you have CSV.jl and Parsers.jl versions that are out of sync (and actually invalid). We have a compat entry to require Parsers.jl 2.2.4 (

Parsers = "2.2.4"
). So updating Parsers.jl should fix this.

@quinnj quinnj closed this as completed Dec 1, 2022
@mbauman
Copy link

mbauman commented Dec 1, 2022

Could we maybe have a patch release to v0.9 that ensures the parsers compat is correct? That minor version doesn't have such a pin and is frequently the one that gets resolved due to the whole ecosystem breaking version bump (edit: I was confusing the v0.8/v0.9 split with this one; not sure what was holding v0.9 back for me here).

Parsers = "2"

@AraujoH
Copy link

AraujoH commented Feb 17, 2023

If I install the latest versions of both CSV.jl and Parsers.jl and I keep seeing the same error, do you have any idea what else could be wrong?

@mbauman
Copy link

mbauman commented Feb 23, 2023

@AraujoH are you sure you have the latest versions? This will happen if you have CSV <= v0.10.4 and Parsers >= v2.2.4, I believe. I've found both can often get held back by other packages.

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