metasoarous/semantic-csv

Option :keyify is ignored

Closed this issue · 7 comments

When you specify both :keyify and :header options to mappify, then :keyify seems to be ignored: the output maps are always produced with "symbolized" column names.

Btw, the source code for "mappify" shown at http://metasoarous.github.io/semantic-csv/ actually works fine, but the actual (transducer-based) implementation has the above issue.

Note that the docs you linked to are outdated; The doc generation system (marginalia) has been breaking on the project for quite some time, preventing me from issuing a new release.

I actually rather think :keyify should be ignored if you specify :header. Specifying header would seem to imply that you know what you want the header to be, and if you want it to be in terms of keywords, then that's what you should pass in. I'm happy to hear a rebuttal to this position, but that's where I stand for the moment.

I agree – it makes sense to ignore :keyify if :header is given. But even if I list the column names as strings there (and do not specify :keyify), they still get converted into symbols 😄

@cordawyn Can you give an example. I don't have that problem when I run the tests. Or maybe I'm missing something.

Given the input file "test.csv":

x;y;z
hello;beautiful;world
good bye;cruel;world

and code:

(defn test
  []
  (with-open [f (io/reader "test.csv")]
    (->>
     (csv/parse-csv f :delimiter \;)
     rest
     (sc/mappify {:header ["a" "b" "c"]})
     doall)))

when I run test, the output is:

({:a "hello", :b "beautiful", :c "world"} {:a "good bye", :b "cruel", :c "world"})

Note that the map keys are :a, :b, :c, but not "a", "b", "c".

Even if I add :keyify false to mappify options, the output still stays the same.

@metasoarous - The behavior @cordawyn is the implemented behaviour. However, I went back to commit 0a9a92a to look at the code prior to the transducer integration. The headers are only transformed into a key if :keyify is truthy. I'm going to make a PR and let you decide how you want to move forward on this one.

My idea was that the headers from :header option stay intact: if you list them as symbols – you get symbols in the output, if you list them as strings – you get strings in the output. I think it would also be convenient in cases where for some reason one would want to use "non-keyifiable" objects for keys. Basically: if :header is given, don't touch the resulting columns (i.e. ignore :keyify), keep them as they are given for :header. I thought that was your idea too.

But regardless, your PR works for me, so you can merge it and close this issue, I guess. Thank you very much for help!

This should be fixed as of @mahinshaw's commit 984308d (merged at
6a8bb7f). Thanks again for raising this issue @cordawyn!