# A test where readcsv and writecsv fail

**URL:** <https://discourse.julialang.org/t/a-test-where-readcsv-and-writecsv-fail/3185>\
**Category:** General Usage\
**Tags:** testing\
**Created:** [April 12, 2017, 8:25pm UTC](https://discourse.julialang.org/t/a-test-where-readcsv-and-writecsv-fail/3185 "2017-04-12T20:25:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [April 12, 2017, 8:25pm UTC](https://discourse.julialang.org/t/a-test-where-readcsv-and-writecsv-fail/3185/1 "2017-04-12T20:25:31Z")

</div>

Consider the following test. It randomly samples from a bunch of symbols, builds a matrix, `writecsv`s it, `readcsv`s it, and then compares the two. It fails with even really small `n`s.

```julia
function genmat(collection, n)
    #randomly collects `n` charachters from String `collection` and fills a 3x2 matrix, saves this matrix to csv file, reads the text of this saved file, and returns both matrices
    c = [i for i in collection]
    x = [join(rand(c, n)) for i = 1:3, j = 1:2]
    writecsv("a.csv", x, quotes = true)
    y = readcsv("a.csv", String, quotes = true)
    return (x, y)
end

collection = """!#¤%"&/()=?*_:;><,.-'§½`'äöåÄÖÅ\\\n\t\b """
n = 1000
x, y = genmat(collection, n)
@assert x == y # this fails with high probabilities even for a really small `n`

```

maybe [this](https://discourse.julialang.org/t/readcsv-julia-0-6-0-not-working-properly/2905/2) is related.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [April 12, 2017, 9:59pm UTC](https://discourse.julialang.org/t/a-test-where-readcsv-and-writecsv-fail/3185/2 "2017-04-12T21:59:21Z")

</div>

It would be good to add `comments=false, skipblanks=false` to `writecsv` and `readcsv` options. And the related thread does fix a bug in the implementation when Unicode characters are included, so using a fixed-up 0.6 master branch would be advisable to find additional errors.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [April 12, 2017, 10:07pm UTC](https://discourse.julialang.org/t/a-test-where-readcsv-and-writecsv-fail/3185/3 "2017-04-12T22:07:03Z")

</div>

Forgot to add, I tested this on the nightly releases [here](https://launchpad.net/~staticfloat/+archive/ubuntu/julianightlies). It might be fine in the more resent versions.

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [April 13, 2017, 8:36am UTC](https://discourse.julialang.org/t/a-test-where-readcsv-and-writecsv-fail/3185/4 "2017-04-13T08:36:34Z")

</div>

Tested with `0.6.0-pre.alpha.293` (2017-03-28) and with the extra options I mentioned and it worked - three times with `n = 1000`.

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [April 13, 2017, 8:38am UTC](https://discourse.julialang.org/t/a-test-where-readcsv-and-writecsv-fail/3185/5 "2017-04-13T08:38:32Z")

</div>

Awesome.  
I guess, just because this doesn’t seem to be a feature, but more of a bug of a pretty basic function (read and write csv files), maybe the fix should trickle down to the older versions of Julia as well?
