Given that you already mention `Datamancer`: At a high level, this is pretty 
much what I do in my CSV parser there. I first check a few N rows at the 
beginning before I begin parsing to deduce the most likely type (e.g. first row 
may be an int by chance, but second then explicit float; to avoid reallocating 
and copying for such common cases). And then I begin parsing and hope the 
deduced type holds. If parsing fails I indeed just fall back to the "next 
higher up type" that can encompass the seen data. It's ugly, but CSV is also an 
ugly data format. Ugly problems sometimes require ugly solutions... :)

Maybe someone smarter than me can tell both of us that there are better ways 
though. ;) 

Reply via email to