d3 / d3-dsv

A parser and formatter for delimiter-separated values, such as CSV and TSV.
https://d3js.org/d3-dsv
ISC License
437 stars 76 forks source link

Only autoType strings #78

Closed tophtucker closed 3 years ago

tophtucker commented 3 years ago

I understand that d3.autoType is somewhat dangerous and only meant to be used in narrow circumstances. But I have still found myself wanting to use it outside the context of d3-dsv, and thus without the guarantee that values will come in as strings. I was happy when data.map(d3.autoType) worked (in a case that happened to be all strings), and then surprised when another time it didn't. (I only came across this thanks to @enjalot!)

(Then again, I also actually initially guessed it'd be part of d3-array, and maybe that oughta be warning to me that this is out of scope; maybe if you were writing a more general-purpose autoType, many things would be different.)

mbostock commented 3 years ago

This will make d3.autoType slower for its intended use case (converting strings into non-strings), so I think this is probably undesirable. What is the situation where you have partially converted some string values but not others?

Fil commented 3 years ago

Related? https://github.com/d3/d3-dsv/pull/54

tophtucker commented 3 years ago

OK I'm convinced! There wasn't really a situation where I had partially converted some string values but not others; there was only a situation where I wanted to charitably accept either converted or unconverted arrays, so the user didn't have to think about it. But I guess that's better handled by checking for unconverted values first.