A straightforward way to extend CSV with metadata
gist.github.com
gist.github.com
Time to retire the CSV? - https://news.ycombinator.com/item?id=28221654 - Aug 2021 (544 comments)
name:String, date:Date, value:Int
"Miami", 2021-08-19 11:54:19.721376-05, 2
And making header mandatory.I think forcing quoting of strings and forcing "," for separation and "\n" for lines. Dates are ISO, decimals use .
That is all.
P.D: This is similar how I done this for my mini-lang https://tablam.org/syntax. Tabular data is very simple and the only problem with csv is that is too flexible and let everyone to change it, but making the "schema" outside from csv is against it purpose.
No doubt, you can use csv in a well defined way if there is agreement and specs. The problem is there simply isn't any defacto standard and it won't be able to establish one in this domain...
Btw. : The python intake package allows you to specify metadata.
RFC4180 is an after-the-fact RFC to try and codify common practices in the industry so some tools may refuse to conform to it - but it's really clearly written and like... super short. If you've never read it just go ahead and do so since it lays things out with exceeding care.
item1,item2,,item4,,,item7
to represent nulls. What do you think the pitfalls are here? (Sincere question, wondering how we can improve.)For a improved CSV, that minutae must be defined from the start, but also must take in account how is CSV used, and keep it spirit.
P.D: A example on something like this is https://commonmark.org, that codify the rules for markdown in a better defined speck.
The only advantage I would see for commas is if you are editing the file in a text editor that doesn't highlight strings (like notepad) so it's hard to distinguish them from spaces
Tabs are trivial to actually type (so they're much off than, say, FormFeed) but they're difficult to visually distinguish. I also think it's generally a good habit to just force quoting of all fields in CSV to dodge any impending user errors.
Human readable file formats have surrendered space efficiency for legibility and the main attribute they need to focus on, IMO, is defense against human errors.
If you need csv to work, pick any one interpretation that does work.
%csvddfVersion: 1.2
%delimiter: ","
%doubleQuote: true
%lineTerminator: "\r\n"
%quoteChar: "\""
%skipInitialSpace: true
%header: true
%commentChar: "#"
%mandatory: address name
%type: address:string
%type: name:string
%type: birthday:date
%type: telephone:number
address,name,birthday,telephone
177A Bleecker Street,Stephen Strange,1963-01-01
Or something like that, where everything up to the first blank line is the schema.For instance in a code signing situation it was socialized that only the archive was 'safe' and you used one of several tools to build them or crack them open. However that company was already used to thinking about physical shipping manifests and so learning by analogy worked, after a fashion.
* format.txt
* mydata.csv
* .DS_Store
It will be there if the zip was created on a Mac so might as well include it in the standard.
If you are serious, then what about just ignoring any files in the zip that are not specified in the standard?
You cant reason your way out of Apple being right _always_.
That said - all sorts of programs that bundle files inject rando metadata files and if there was a codified standard it should be flexible enough to ignore these files (possibly agreeing to never require any files to function that lead with a `.` since most of the random junk that gets thrown into zip files tends to at least consistently follow that habit.
This would be better, IMHO:
csvddfVersion: 1.2
delimiter: ";"
doubleQuote: true
lineTerminator: "\r\n"
quoteChar: "\""
skipInitialSpace: true
header: true
commentChar: "#"I don't really see a need for a metadata file, nor would I ever see Excel or other tools accepting it. The main problem is adoption, CSV isn't perfect but it's what we have. Now if you wrote this as a member of the Excel team at Microsoft, and then Excel had the option of exporting CSV files with a metadata file, then I'd be a bit more excited.
Where I work we have offices in the US, and in Europe where installing a localized version of windows will swap ',' and '.' when used as the group and decimal separator. Excel when loading a value 100,002 in the US will see one hundred thousand and two, in some parts of Europe it will see one hundred and 2 thousandths.
Character set handing can be just as bad, there is no good way to get Excel to auto open a CSV file as UTF-8 that won't break every other CSV parser in existence. The only cross platform option is ASCII. Excel will happily load your local OS encoding, likely some variant of ISO-8859, but any other encoding requires jumping through hoops.
Here are a couple of cases that I run into frequently:
* Excel is very aggressive about forcing type conversion based on its own assumptions. It will convert strings to dates or numbers, even if data is lost in the process. It will ignore quotes to convert long numeric IDs into scientific notation which truncates the ID unrecoverable.
* Excel cannot deal with quoted strings containing line breaks. It treats them as separate records and you get truncated records and partial records on separate rows.
Zip codes that lose leading zeros.
Gene names that get converted to dates. The names of some genes were recently changed because too many databases were being corrupted by researchers using Excel to read CSV files: https://www.theverge.com/2020/8/6/21355674/human-genes-renam...
Source: dealing with CSV files people exported from Excel and the horrors that flowed from there.
It can't do this because it confuses such files with files in SYLK format, which was YET ANOTHER attempt to standardize spreadsheet data interchange, dating from the 80s.
I always view CSV as a lowest common denominator, of course more precise formats exist, but not everyone can use those. Csvs normally get the job done, but like anything else you need to know it's limitations. Something like a basic phone book should work, your scientific data, with dozens upon dozens of floating point numbers may not work.
There just aren't that many widely used applications that deal with things like this, but Google sheets seems to be the obvious one.
For me personally, I usually view things in Excel/LO but don't save, and if I need to modify anything I'll use a text editor for one-off changes, or I'll use something like Python with the pandas library for more programmatic changes. Pandas does have issues forcing timestamps to convert sometimes, but that can be easily configured. Otherwise, no problems with this method.
There's definitely a lot of friction if you want to edit .CSV's without your formatting/encoding being altered, unfortunately.
LibreOffice does a similar amount of clobbering, but in general it notifies you of any would-be clobbering and allows you to abort beforehand, which is really nice. I still avoid exporting via LibreOffice though for very sensitive situations, but it is noticeably better still.
If the user does Data > From Text/CSV > Transform > use PowerQuery to set the first row as the header, I think it's true that Excel does a good job. It provides the basics at least: configurable charset and column type detection. When the user re-saves to CSV, I'm not aware of any way to configure the output (e.g., force quotation of text content), but that's sort of ok.
The easy path—double clicking on a CSV file or using File > Open—is where all the weird auto-conversion of values happens. But other posts have covered that part.
You can't even hope to keep a file intact upon opening...
Excel has the most inexplicably horrific handling of long number strings that it is borderline unusable.
https://excel.uservoice.com/forums/304921-excel-for-windows-...
If you think CSV is complicated for your app requirement choose a different delimiter like pipe, else look at other alternatives. Simple as that.
I’ve spent years building parsers for different document in the retail juggernaut businesses.
1. select sane defaults on all of those options and
2. create a new file extension (.scsv for strict csv or sth)
and call it a day
_edit_
Oh, someone already did it: https://github.com/code4fukui/StrictCSV
If you can decide this file format, couldn't you just normalize the CSV file instead?
I'm assuming it's in response to the post yesterday that outlined all the things that are wrong with CSV and how other formats like Parquet are better.
I know I had specific conversations about CSV versus XML and those referred to a substantial body of literature on the topic.
Perl6 tried incorporating non-US-keyboard characters into the language and that went very badly. I'm sure it works fine for Perl6 people, but beyond that boundary, I still encounter people who can't type é on a Mac with the keyboard alone today, much less handle Alt-001E. So I am extremely pessimistic.
We do not need a new format. There are numerous superior options if we're just going to provide a different format (parquet, avro, orc, etc).
1. There are way too many standards, we have n standards
2. The ecosystem is fragmented and we have to let them talk to each other
3. I think we should solve it by introducing our new standard
4. We now have n+1 standards
And I am not saying I have solution.
A priori, the design space I'd want to look at is something between protobuf and csv. Perhaps optionally at the end of each line [somewhere non-breaking] you add metadata for that line, including specifying a parser implementation you know can perform perfectly.
The OP suggestion might address this if metadata(s) could apply to particular ranges of lines. It would be more fragile to the extent of being in different file.
[0]: https://raw.githubusercontent.com/csv-ld/ns/main/2021-05-csv...
Magic comment with field labels is required, and you can then use the usual unix tools for processing. It's magical.