# CSV.write writeshortest error

**URL:** <https://discourse.julialang.org/t/csv-write-writeshortest-error/90336>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 16, 2022, 9:57am UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336 "2022-11-16T09:57:26Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [November 16, 2022, 9:57am UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/1 "2022-11-16T09:57:26Z")

</div>

I have been trying for several days to save a dataframe and cannot seem to avoid the same recurring error.

Here is the beginning of my file:

```julia
df_rtns6[1:5,1:5]

	Date	AAPL_Close	ABT_Close	ADBE_Close	AIG_Close
String	Float64	Float64	Float64	Float64
1	2000-01-04	-0.08431	-0.0285714	-0.0838894	-0.0511125
2	2000-01-05	0.0146332	-0.00183822	0.0197711	0.00237643
3	2000-01-06	-0.0865383	0.0349907	0.00816327	0.0305042
4	2000-01-07	0.0473689	0.0106762	0.048583	0.0748466
5	2000-01-10	-0.0175879	-0.00704224	0.03861	-0.0176941

```

and here is my write statement

```julia
CSV.write("Rtns_FF_Factors.csv",df_rtns6);

```

The output is always something like:

```julia
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 ~/.julia/packages/CSV/jFiCn/src/write.jl:444
  [2] (::CSV.var"#106#107"{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 ~/.julia/packages/CSV/jFiCn/src/write.jl:371
  [3] eachcolumn
    @ ~/.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{(:Date, :AAPL_Close, :ABT_Close, :ADBE_Close, :AIG_Close, :AMGN_Close, :AMT_Close, :AMZN_Close, :AXP_Close, :BA_Close, :BAC_Close, :BK_Close, :BKNG_Close, :BLK_Close, :BMY_Close, :C_Close, :CAT_Close, :CL_Close, :CMCSA_Close, :COF_Close,

```

and similar, then a bit further down:

```julia
DataFrames.DataFrameRows{DataFrame}, CSV.Options{UInt8, UInt8, Nothing, Tuple{}, typeof(CSV._identity)}, Vector{UInt8}, Int64, Int64, NTuple{85, Symbol}}, io::Any, append::Bool, compress::Bool)

```

I checked for ‘nothings’ and missing values and there are none.

I would be grateful for any help

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [November 16, 2022, 10:39am UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/2 "2022-11-16T10:39:33Z")

</div>

This might be a version conflict between CSV and Parsers.  
Update both packages to the newest version should fix this.  
Downgrading Parsers to 2.4.0 should also work.

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [November 16, 2022, 10:47am UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/3 "2022-11-16T10:47:26Z")

</div>

> [@Rudi79](#):
>
> Update both packages to the newest version should fix this.

Thank you for your suggestions.

I have recently run Pkg.update(), so unfortunately I don’t think your first suggestion will work.

I never knowingly installed Parsers before. I worry a bit that downgrading might break something else(?)

In the meantime, writedlm worked easily for me, so I guess I will have to avoid CSV.jl for now.  
Thanks

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 16, 2022, 2:30pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/4 "2022-11-16T14:30:19Z")

</div>

What version of packages are you on? Please post the output of `] st`

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [November 16, 2022, 9:06pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/5 "2022-11-16T21:06:04Z")

</div>

Hi. Thanks for taking a look.

```julia
julia> Pkg.status("CSV")
Status `~/.julia/environments/v1.8/Project.toml`
⌃ [336ed68f] CSV v0.10.4
Info Packages marked with ⌃ have new versions available

julia> Pkg.status("Parsers")
No Matches in `~/.julia/environments/v1.8/Project.toml`

```

I updated CSV, so now

```julia
julia> Pkg.status("CSV")
Status `~/.julia/environments/v1.8/Project.toml`
  [336ed68f] CSV v0.10.7

```

I’ll try it out and let you know (hope nothing else breaks!)

Thanks

---

<div class="post-metadata">

**Author:** ![greivin](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@greivin](https://discourse.julialang.org/u/greivin)\
**Post date:** [November 18, 2022, 4:41pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/6 "2022-11-18T16:41:19Z")

</div>

Did you manage to fix it? I have the exact same problem

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [November 18, 2022, 4:58pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/7 "2022-11-18T16:58:41Z")

</div>

I haven’t been able to test whether the upgrade helped yet, as I  
can’t afford to lose my data by restarting just now. I did manage  
to get around it using writedlm

---

<div class="post-metadata">

**Author:** ![greivin](https://avatars.discourse-cdn.com/v4/letter/g/a6a055/32.png) [@greivin](https://discourse.julialang.org/u/greivin)\
**Post date:** [November 18, 2022, 5:07pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/8 "2022-11-18T17:07:48Z")

</div>

It is strange because the same instruction was working fine a few minutes ago and now it is not, maybe there’s a bug in some Julia update? I have both the last version of CSV plus the last version of Parsers and I’m having this trouble. Do you know how to downgrade parsers?

---

<div class="post-metadata">

**Author:** ![flare9x](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/flare9x/32/44537_2.png) [@flare9x](https://discourse.julialang.org/u/flare9x)\
**Post date:** [November 21, 2022, 9:06pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/9 "2022-11-21T21:06:56Z")

</div>

having some issue here as well - moving from atom over to vscode - running julia 1.7 and updated to latest packages. never had an issue prior.

---

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [November 27, 2022, 4:50am UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/10 "2022-11-27T04:50:40Z")

</div>

Converting the entire data frame content into string type worked for me

CSV.write(“temp.csv”,string.(df))

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [November 30, 2022, 3:13pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/11 "2022-11-30T15:13:12Z")

</div>

That seems a good workaround, so long as it doesn’t add quotes to everything.  
It would be lovely if someone knew how to fix this.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 30, 2022, 3:30pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/12 "2022-11-30T15:30:53Z")

</div>

Can you create a MWE that illustrates the problem? Something we can copy and paste to debug.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 30, 2022, 3:41pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/13 "2022-11-30T15:41:26Z")

</div>

Yes an MWE would be good - converting to string is certainly not an acceptable solution for most usecases.

Here’s an example MWE:

```julia
(jl_AHCSuc) pkg> st CSV DataFrames
Status `C:\Users\ngudat\AppData\Local\Temp\jl_AHCSuc\Project.toml`
  [336ed68f] CSV v0.10.7
  [a93c6f00] DataFrames v1.4.3

julia> using CSV, DataFrames, Dates

julia> df = DataFrame(Date = Date(2000):Day(1):Date(2000, 1, 5), AAPL_Close = randn(5), ABT_Close = randn(5), ADBE_Close = randn(5), AIG_Close = randn(5))
5×5 DataFrame
 Row │ Date AAPL_Close ABT_Close ADBE_Close AIG_Close
     │ Date Float64 Float64 Float64 Float64
─────┼───────────────────────────────────────────────────────────
   1 │ 2000-01-01 -1.67331 0.501665 -0.471492 0.685009
   2 │ 2000-01-02 0.832788 -0.47307 0.648369 -0.0362069
   3 │ 2000-01-03 1.22546 -0.517133 0.505574 0.282108
   4 │ 2000-01-04 1.10711 -1.23482 -0.993789 0.325811
   5 │ 2000-01-05 -1.08964 -1.01078 0.306837 -0.956466

julia> CSV.write("Rtns_FF_Factors.csv", df)
"Rtns_FF_Factors.csv"

```

so I can’t replicate this - do you get the same error if you only write the first five rows/columns so is there a specific issue with a certain row/column of your data?

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [November 30, 2022, 3:54pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/14 "2022-11-30T15:54:47Z")

</div>

> [@nilshg](#):
>
> do you get the same error if you only write the first five rows/columns so is there a specific issue with a certain row/column of your data?

Hi Thanks for taking a look. I tried just looking at the first few rows (or columns) of the dataset.

I do recall seeing question marks (‘?’) showing before the ‘Float64’ at the top, even though I made sure there were no missing values or nothings or Inf’s anywhere. I could not get rid of those, though the Matrix() command on the columns worked fine.

I will send an MWE tomorrow, (as I have to give a lecture!)

Thanks!

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [November 30, 2022, 4:24pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/15 "2022-11-30T16:24:02Z")

</div>

Are you running your code inside of Juno? Or any other environment that might load packages in multiple stages, while changing environments?

---

<div class="post-metadata">

**Author:** ![SebastianM-C](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sebastianm-c/32/2480_2.png) [@SebastianM-C](https://discourse.julialang.org/u/SebastianM-C)\
**Post date:** [December 1, 2022, 3:44pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/16 "2022-12-01T15:44:08Z")

</div>

Hi! With the following I’m able to reproduce the issue

```julia
(@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
─────┼──────────
   1 │ 0.100739
   2 │ 0.346434
   3 │ 0.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

```

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [December 1, 2022, 4:44pm UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/17 "2022-12-01T16:44:40Z")

</div>

Updating CSV will surely fix the issue, but often folks are stuck at v0.9.x due to other compatibility concerns. To work around it, you can pin Parsers.jl to `v2.2.4`:

Here’s the “fixed” version from @SebastianM-C’s MWE:

```julia
(@v1.7) pkg> activate --temp
  Activating new project at `/var/folders/cb/h4ftb1y11ls5khbqltqswsl40000gn/T/jl_EsGAnk`

(jl_EsGAnk) pkg> add CSV@v0.9.11
    Updating registry at `~/.julia/registries/General.toml`
    Updating registry at `~/.julia/registries/JuliaComputingRegistry.toml`
    Updating registry at `~/.julia/registries/JuliaSimRegistry.toml`
    Updating registry at `~/.julia/registries/PumasRegistry.toml`
    Updating registry at `~/.julia/registries/TestRegistry.toml`
    Updating registry at `~/.julia/registries/githubjuliaregistryjdb.toml`
    Updating registry at `~/.julia/registries/gitlabjuliaregistryjdb.toml`
   Resolving package versions...
    Updating `/private/var/folders/cb/h4ftb1y11ls5khbqltqswsl40000gn/T/jl_EsGAnk/Project.toml`
  [336ed68f] + CSV v0.9.11
    Updating `/private/var/folders/cb/h4ftb1y11ls5khbqltqswsl40000gn/T/jl_EsGAnk/Manifest.toml`
  [336ed68f] + CSV v0.9.11
  [944b1d66] + CodecZlib v0.7.0
  [34da2185] + Compat v4.5.0
  [9a962f9c] + DataAPI v1.13.0
  [e2d170a0] + DataValueInterfaces v1.0.0
  [48062228] + FilePathsBase v0.9.20
  [842dd82b] + InlineStrings v1.3.2
  [82899510] + IteratorInterfaceExtensions v1.0.0
  [bac558e1] + OrderedCollections v1.4.1
  [69de0a69] + Parsers v2.5.1
  [2dfb63ee] + PooledArrays v1.4.2
  [91c51154] + SentinelArrays v1.3.16
  [66db9d55] + SnoopPrecompile v1.0.1
  [3783bdb8] + TableTraits v1.0.1
  [bd369af6] + Tables v1.10.0
  [3bb67fe8] + TranscodingStreams v0.9.9
  [ea10d353] + WeakRefStrings v1.4.2
  [56f22d72] + Artifacts
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [9fa8497b] + Future
  [b77e0a4c] + InteractiveUtils
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [a63ad114] + Mmap
  [de0858da] + Printf
  [9a3f8284] + Random
  [ea8e919c] + SHA
  [9e88b42a] + Serialization
  [8dfed614] + Test
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode
  [e66e0078] + CompilerSupportLibraries_jll
  [4536629a] + OpenBLAS_jll
  [83775a58] + Zlib_jll
  [8e850b90] + libblastrampoline_jll

(jl_EsGAnk) pkg> add DataFrames
   Resolving package versions...
    Updating `/private/var/folders/cb/h4ftb1y11ls5khbqltqswsl40000gn/T/jl_EsGAnk/Project.toml`
  [a93c6f00] + DataFrames v1.4.3
    Updating `/private/var/folders/cb/h4ftb1y11ls5khbqltqswsl40000gn/T/jl_EsGAnk/Manifest.toml`
  [a8cc5b0e] + Crayons v4.1.1
  [a93c6f00] + DataFrames v1.4.3
  [864edb3b] + DataStructures v0.18.13
  [59287772] + Formatting v0.4.2
  [41ab1584] + InvertedIndices v1.2.0
  [b964fa9f] + LaTeXStrings v1.3.0
  [e1d29d7a] + Missings v1.0.2
  [08abe8d2] + PrettyTables v2.2.2
  [189a3867] + Reexport v1.2.2
  [a2af1166] + SortingAlgorithms v1.1.0
  [892a3eda] + StringManipulation v0.3.0
  [3fa0cd96] + REPL
  [6462fe0b] + Sockets
  [2f01184e] + SparseArrays
  [10745b16] + Statistics

(jl_EsGAnk) pkg> add Parsers@v2.2.4
   Resolving package versions...
   Installed Parsers ─ v2.2.4
    Updating `/private/var/folders/cb/h4ftb1y11ls5khbqltqswsl40000gn/T/jl_EsGAnk/Project.toml`
  [69de0a69] + Parsers v2.2.4
    Updating `/private/var/folders/cb/h4ftb1y11ls5khbqltqswsl40000gn/T/jl_EsGAnk/Manifest.toml`
  [69de0a69] ↓ Parsers v2.5.1 ⇒ v2.2.4
Precompiling project...
  4 dependencies successfully precompiled in 7 seconds (28 already precompiled)

julia> using DataFrames, CSV

julia> df = DataFrame(:a=>rand(3))
3×1 DataFrame
 Row │ a
     │ Float64
─────┼──────────
   1 │ 0.687344
   2 │ 0.577659
   3 │ 0.318793

julia> CSV.write("a.csv", df)
"a.csv"

```

Cf.

> <https://github.com/JuliaData/CSV.jl/issues/1056>
>
> https://discourse.julialang.org/t/csv-write-writeshortest-error/90336

---

<div class="post-metadata">

**Author:** ![eotero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eotero/32/36642_2.png) [@eotero](https://discourse.julialang.org/u/eotero)\
**Post date:** [February 18, 2023, 12:00am UTC](https://discourse.julialang.org/t/csv-write-writeshortest-error/90336/18 "2023-02-18T00:00:51Z")

</div>

did for me too. Thanks!
