# CSV.jl error - cannot convert an object of type WeakRefString

**URL:** <https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603>\
**Category:** General Usage\
**Created:** [September 6, 2018, 1:58am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603 "2018-09-06T01:58:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 6, 2018, 1:58am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/1 "2018-09-06T01:58:02Z")

</div>

Any idea what how i can work around this error? This is Julia 0.6.

```julia
julia> df = CSV.read(file);

MethodError: Cannot `convert` an object of type WeakRefString{UInt8} to an object of type Missings.Missing
This may have arisen from a call to the constructor Missings.Missing(...),
since type constructors fall back to convert methods.

Stacktrace:
 [1] setindex!(::Array{Missings.Missing,1}, ::WeakRefString{UInt8}, ::Int64) at ./array.jl:583
 [2] streamto!(::DataFrames.DataFrameStream{Tuple{CategoricalArrays.CategoricalArray{Union{Missings.Missing, String},1,UInt32,String,CategoricalArrays.CategoricalString{UInt32},Missings.Missing},Array{Union{Int64, Missings.Mi

```

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [September 6, 2018, 2:38am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/2 "2018-09-06T02:38:12Z")

</div>

You could try [CSVFiles.jl](https://github.com/queryverse/CSVFiles.jl) and see whether that works better.

---

<div class="post-metadata">

**Author:** ![wfrgra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wfrgra/32/10702_2.png) [@wfrgra](https://discourse.julialang.org/u/wfrgra)\
**Post date:** [September 6, 2018, 3:52am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/3 "2018-09-06T03:52:13Z")

</div>

Try `df = CSV.read(file,rows_for_type_detect=100000)`. CSV tries to detect the column types, but falls over if it finds a later value that cannot be parsed into the type

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 6, 2018, 4:55am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/4 "2018-09-06T04:55:58Z")

</div>

This is a bit unexpected…

```julia
julia> @time df = DataFrame(CSVFiles.load(file))

MethodError: no method matching load(::String)
Closest candidates are:
  load(::FileIO.File{FileIO.DataFormat{:TSV}}) at /opt/julia/share/julia/site/v0.6/CSVFiles/src/CSVFiles.jl:26
  load(::FileIO.File{FileIO.DataFormat{:CSV}}) at /opt/julia/share/julia/site/v0.6/CSVFiles/src/CSVFiles.jl:22
  load(::FileIO.File{FileIO.DataFormat{:CSV}}, ::Any; args...) at /opt/julia/share/julia/site/v0.6/CSVFiles/src/CSVFiles.jl:22
  ...

```

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [September 6, 2018, 5:29am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/5 "2018-09-06T05:29:02Z")

</div>

`load` is not a `CSVFiles` function, it is just reexported from `FileIO` 🙂 So you want to either call `FileIO.load` or just do a `using CSVFiles` and then simply `DataFrame(load(file))`. At least I hope that is the bug, if not, could you send over the versions of the packages you are using?

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 6, 2018, 6:21am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/6 "2018-09-06T06:21:21Z")

</div>

That works! Thanks

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 6, 2018, 6:23am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/7 "2018-09-06T06:23:56Z")

</div>

@davidanthoff - you’re right. However, for some reasons, I am sitll unable to load the file (which is not too big, around 700 MiB). It got pegged at 100% cpu for 30 minutes and I gave up. Same thing with TextParse.jl if I use that directly.

CSV.jl does work and it took about 2.5 minutes to load the file.

---

<div class="post-metadata">

**Author:** ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Post date:** [September 6, 2018, 6:24am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/8 "2018-09-06T06:24:48Z")

</div>

What are CSVFiles’ advantages over CSV? Is CSV being migrated to CSVFiles?

---

<div class="post-metadata">

**Author:** ![johann.spies](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johann.spies/32/8805_2.png) [@johann.spies](https://discourse.julialang.org/u/johann.spies)\
**Post date:** [September 6, 2018, 7:31am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/9 "2018-09-06T07:31:12Z")

</div>

> [@davidanthoff](#):
>
> `using CSVFiles` and then simply `DataFrame(load(file))`

I found an interesting difference between 0.6.4 and Julia 1.0

On 0.6.4:

```julia-auto
using DataFramesMeta, CSVFiles, BenchmarkTools, DataFrames

@btime df = DataFrame(load("/home/js/db_docs/sql/projects/dhet-journals/aantal_publikasies_in_joernaal.csv"))
 18.232 ms (215666 allocations: 16.92 MiB)
13222×7 DataFrames.DataFrame. Omitted printing of 6 columns

julia> using CSV

julia> @btime df = DataFrame(CSV.read("/home/js/db_docs/sql/projects/dhet-journals/aantal_publikasies_in_joernaal.csv"))

 43.821 ms (861124 allocations: 22.19 MiB)
13222×7 DataFrame. Omitted printing of 6 columns

```

On 1.0

```julia-auto
using DataFramesMeta, CSVFiles, BenchmarkTools, DataFrames

 @btime df = DataFrame(load("/home/js/db_docs/sql/projects/dhet-journals/aantal_publikasies_in_joernaal.csv"))
  1.144 s (9190647 allocations: 208.81 MiB)
13222×7 DataFrame. Omitted printing of 6 columns

julia> using CSV

julia> @btime df = DataFrame(CSV.read("/home/js/db_docs/sql/projects/dhet-journals/aantal_publikasies_in_joernaal.csv"))
julia> using CSV

julia> @btime df = DataFrame(CSV.read("/home/js/db_docs/sql/projects/dhet-journals/aantal_publikasies_in_joernaal.csv"))

17.901 ms (354395 allocations: 9.85 MiB)
13222×7 DataFrame. Omitted printing of 6 columns

  

```

The 1.0 version is 61 times slower and makes nearly 43 times more allocations with CSVFiles and a little bit faster using CSV.

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 6, 2018, 7:44am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/10 "2018-09-06T07:44:14Z")

</div>

That seems to match up with what I just experienced. I switched over to 0.7 when I ran `DataFrame(load(file))` earlier and it never came back.

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [September 7, 2018, 5:45am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/11 "2018-09-07T05:45:05Z")

</div>

[CSVFiles.jl](https://github.com/queryverse/CSVFiles.jl) is not yet ready on julia 1.0 (I only recommended it because the original question mentioned julia 0.6). It runs, but _really_ slowly (as you discovered). There is a nasty performance problem that crept into [TextParse.jl](https://github.com/JuliaComputing/TextParse.jl) when it was ported to julia 1.0, see [here](https://github.com/JuliaComputing/TextParse.jl/issues/73). I have no doubt we will be able to fix that, but right now that is there.

@tk3369: did things also not work on julia 0.6, or did you only try on julia 0.7?

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [September 7, 2018, 6:19am UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/12 "2018-09-07T06:19:47Z")

</div>

Does not work in 0.6 either. It’s been half an hour and still hasn’t finished.  
Also, I have to `using FileIO` or else the `load` function isn’t defined.

My config:

```julia
julia> versioninfo()
Julia Version 0.6.2
Commit d386e40c17 (2017-12-13 18:08 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) CPU E5-2699 v4 @ 2.20GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, broadwell)

julia> Pkg.status("CSVFiles")
 - CSVFiles 0.5.1

julia> Pkg.status("TextParse")
 - TextParse 0.4.1

```

---

<div class="post-metadata">

**Author:** ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)\
**Post date:** [October 13, 2018, 10:13pm UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/13 "2018-10-13T22:13:00Z")

</div>

Hm, that is a really old version of CSVFiles.jl that you are getting there… The exported `load` and `save` functions were added in v0.6.0…

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [October 13, 2018, 10:14pm UTC](https://discourse.julialang.org/t/csv-jl-error-cannot-convert-an-object-of-type-weakrefstring/14603/14 "2018-10-13T22:14:57Z")

</div>

No worries… I’ve already moved on to 1.0 and have been playing with the master of that ecosystem 🙂
