Repository navigation
v2.0.0
Breaking changes
The API is unchanged, but sniffed output can differ in ways callers may depend on:
fields,typesandnum_fieldsnow always have the same length (see Changed). Callers that matchedfieldsto the header row's width can see extra generatedfield_Nnames- Reported
num_preamble_rows,has_header_rowandfieldschange on some messy files: a lone header row of a different width is now taken as the header (#67), and a ragged table is no longer reported as mostly preamble (#79) Sniffer::quote()now restricts the candidates even withoutSniffer::delimiter()- The
§delimiter candidate is removed, and the CLI's--delimiter/--quotereject non-ASCII and multi-character values instead of silently truncating them
Performance
- The double-quote region statistics behind the quoted-delimiter demotion (trusted boundary separators, per-delimiter inside/outside counts, and the smallest trusted boundary field count) depend only on the sample, but every candidate dialect recomputed them with several full passes over the sample. They are now computed once per sniff and shared by every candidate; the inside/outside counts take one pass for all delimiters, and the two other statistics share one trusted-separator scan
- That work, and the quote-boundary counts, now run alongside table parsing instead of before or after it: parsing keeps at most one thread busy per distinct parse (6 on the profiled test file), so on machines with more cores than that the extra work runs on threads that would otherwise sit idle
- Parsed tables store all their cells back to back in one string, with an offset per cell, instead of one
Stringper cell. A large sample parses into millions of cells per candidate table, and allocating and freeing each one dominated parsing and memory: freeing the five unused candidate tables alone took ~20% of a 150 MB--allrun - Net effect of the above on a release build, measured against the code before these changes:
--allon a 150 MB / 1.66M-row 8-column file drops from 2.96 s to 1.63 s (−45%) on 16 cores and from 9.2 s to 6.8 s (−27%) single-threaded (RAYON_NUM_THREADS=1); across 150 MB, 48 MB and 60 MB files, −31% to −47% on 16 cores, −32% to −43% on 4, and −22% to −35% on 1;-b 10MiBdrops from 212 ms to 122 ms. Peak memory with--allfalls by half or more: 3.23 → 1.53 GB on the 150 MB file, 2.11 → 1.01 GB on a 48 MB quoted file, and 2.13 → 0.58 GB (−73%) on a 60 MB file of small integers. Default sampling (100 records) is unchanged; its ~9 ms is dominated by process startup. Neither performance change alters output: each was verified byte-identical against the code immediately before it (all five benchmark suites, the JSON output for all 548 corpus files with default sampling and with--all, and the large test files, including atRAYON_NUM_THREADS=1). The timings above compare against the code before both, so they span the #67 and #68 output fixes, which do not affect speed
Changed
fields,typesandnum_fieldsin sniffedMetadatanow always have the same length: the wider of the header row and the most common width of the data rows (the header row does not count toward that width, so it cannot decide a tie). Previouslytypesused the data rows' modal width andfieldsthe header row's width, so they could disagree (e.g. 3 field names but 2 types), and the CLI's verbose output silently dropped the extra columns. A header row shorter than the records is padded with generatedfield_Nnames; a detected header row wider than the records keeps every name and widensnum_fieldsto match. (A header that structural preamble detection used to set aside as preamble is covered by the #67 entry under Fixed.) Across the 548 benchmark corpus files this changes 12 JSON outputs with default sampling and 13 with--all, all of which gain names or types and none of which lose one;num_fieldschanges forphonography_lib.csv(17 → 21) and, with--all,file_multitable_more.csv(9 → 10)- Dialect tiebreaking is anchored to the top score: every candidate within 5% of the best gamma competes on delimiter priority, then quote priority, then gamma. The previous pairwise "within 5%" comparison was not transitive and could chain through successive close scores to a candidate well below the top (e.g.
\t1.00 →;0.96 →,0.92 picked,). No benchmark corpus file is affected
Removed
- The section sign (
§,0xA7) delimiter candidate. Input is transcoded to UTF-8 before parsing, where§is two bytes, and thecsvreader splits on a single byte, so a§-delimited file could never be detected (or even parsed with--delimiter §). Candidates drop from 33 to 30; benchmark results are unchanged
Fixed
- A byte-limited sample (
SampleSize::Bytes,-b) usually ends in the middle of a record, and that cut-off fragment was parsed and scored as a short row (#75). On wide files the extra width change could flip the detected dialect:S30out.csvandW44out.csvdetected;, which never occurs in them, at every sample size up to 24 KiB. When a read fills the sample and more input follows, the sample now ends at its last line break. A complete final record without a trailing newline is kept (the sample is only trimmed when more input is known to follow), as is a sample with no line break, one where the trim would drop more than half of it, and UTF-16 input.SampleSize::Recordsgets the same treatment when its byte estimate cuts a record;SampleSize::Allis unchanged. Results:- Byte samples: at 8 KiB, 14 corpus files change delimiter, all to the annotated one and none away from it; at 64 KiB, 4 more. Neither size breaks a delimiter that was right before.
S30out.csv/W44out.csvdetect,at every size from 2 KiB to 24 KiB. Files no larger than the sample are byte-identical. Many outputs lose a spuriousflexible: true - Default sampling: all five benchmark suites are identical. 4 of 548 JSON outputs change: small
avg_record_lenshifts,data_gov_catalog.csvno longer reported as ragged, anddict.csvnow detected as GBK (annotatedgb2312) instead ofwindows-1252, because the sample no longer ends halfway through a two-byte character.--allis identical - Known limit: on ragged parses, structural preamble detection can report a long preamble near the end of the table. The cut-off fragment used to mask this in byte samples (e.g.
diamonds.csvat 256 KiB now reports 3629 preamble rows instead of 0), and default sampling already shows it (file_field_delimiter_0x20.csv, 83 rows); fixed by #79, below. The CLI's URL sampling (--features http) fetches a byte range directly and is not trimmed yet
- Byte samples: at 8 KiB, 14 corpus files change delimiter, all to the annotated one and none away from it; at 64 KiB, 4 more. Neither size breaks a delimiter that was right before.
- A file of stacked tables with different widths could be reported with a delimiter that never occurs in it and one field, e.g.
S30out.csvandW44out.csvwith--allgave;(#72). Whenever a table wider than 100 fields was the most common width, the high-field penalty halved the real delimiter's score. That score was already near zero on the consistency term (tau_0 uses the absolute spread of field counts), so it fell below the uniform one-field parse shared by every absent delimiter. Candidates whose modal width is one field are now left out of the selection whenever some candidate parses to more than 50 fields with the width changing on at most 1 in 20 row boundaries, over at least 10 rows (wrongly split text changes width on most rows; stacked tables only between blocks). This also covers a delimiter that occurs only once or twice, such as one stray;. The exception is a candidate whose delimiter is among those wide parses' delimiters and that is one field on every record: there quoting merged the wide parse into one field, so a single column of"x,x,…,x"values stays one double-quoted field. A candidate that is one field on most rows only (e.g. stray apostrophes folding rows together under'quoting) gets no exception. The high-field penalty itself is unchanged, so a uniform wrong parse still cannot outscore the real delimiter: e.g. a headerlessid<TAB>v1,…,v120file stays tab-delimited, and one or two long lines of prose stay one field. Both files now detect,with--all, with-n 100…302, and (with the #75 fix below) at every byte sample size tested, 2 KiB to 256 KiB; the rest of the corpus is byte-identical, including all five benchmark suites, and long single-column prose still stays one field. Known limits: a steady narrow parse of another delimiter (e.g. anR&Dcell in every row) can still beat a wide stacked table (#76); many short stacked tables, where widths change on more than 1 in 20 rows, still fail;num_fieldsstill follows whichever table dominates the sample; and a column-aligned table with exactly two spaces between columns now detects space (with empty fields between) instead of one column - On a ragged parse, structural preamble detection could report most of the table as preamble (#79). It took the first row of the most common width from which at least 80% of the remaining rows had that width. When that width is scattered through the table, the condition only holds near the end, so e.g.
file_field_delimiter_0x20.csvreported 83 of 84 rows as preamble anddiamonds.csvat-b 262144reported 3629. The preamble now ends at the first row of the most common width; if the 80% condition does not hold from there, there is no structural preamble. Delimiter, quote and all five benchmark suites are unchanged. Only files whose reported preamble held rows of the table's own width change: 8 of 548 with default sampling, 10 with--all, and 10/10/11 at 8/64/256 KiB byte samples- Headers recovered:
test052.csv(header, two stray#rows, then data: preamble 3 → 0),linodef_bueditor_button.csv(4 → 0),file_quotation_char_0x27.csv(43 → 0), andfile_field_delimiter_0x2C_0x20.csvat 8 KiB (30 → 0) now report their real header.limesurvey_survey_94328.csvreports its first table, 35 fields with its header, instead of 57 preamble rows and one field - Preamble dropped to the comment rows or 0:
file_field_delimiter_0x20.csv(83 → 0),baselog.csv(71 → 0),artists.csv(up to 1474 → 0),diamonds.csvat 256 KiB (3629 → 0),weapondef.csv(67 → its 35 comment rows),events-listing.csv(2 → 0; its header is still not recognised as one) - Known limits:
iometeroutput.csvkeeps its 13-row preamble with default sampling and at 8 KiB, but reports 0 with--all, 64 KiB and 256 KiB (previously 951, 281 and 951): from its first 56-field row, only about 78% of the remaining rows have 56 fields (832 of 1065 with--all), just under the 80% needed. And a non-tabular block that begins with a line of the table's width, e.g. a 5-field title line, 30 note lines, then a 5-column table, now reports no preamble: the title stays in the table, where it may be taken as the header; field counts cannot tell it apart from a header followed by stray rows, as intest052.csv
- Headers recovered:
- A header row whose width differs from the data rows was reported as a one-row structural preamble, so
fieldscame out as generated names or as the first data row (#67). This happens with trailing delimiters, Rwrite.tableheaders that omit the row-name column, and missing or extra separators. When exactly one row is set aside, it is now taken as the header if it has at least two fields and no numbers or dates and the next row has a number or date. One-field title lines, titles containing numbers, and title lines above a text header stay preamble, and longer preambles are unchanged. Across the 548 benchmark corpus files this restores the header of 20 files with default sampling and 18 with--all; nothing else changes (delimiter, quote and all five benchmark suites are identical).num_fieldsgrows where the header is wider than the data:Batch_3250493_batch_results.csv28 → 30,CalculusComponents.csv4 → 6,JV_newsite_IBC_current_20110517.csv19 → 21,set001.csv9 → 11,row_more_sep_row0_col0.csv9 → 10, and (default sampling)S30out.csv/W44out.csv301 → 302 Sniffer::quote()was ignored unlessSniffer::delimiter()was also set; a forced quote now restricts the candidates on its own- CLI
--delimiter/--quotesilently truncated a non-ASCII character to its low byte (-d €became0xAC,¬), and--quoteused only the first character of a longer value. Both now require a single ASCII character (--quotealso acceptsnone) and reject anything else with an error
Full Changelog: v1.4.0...v2.0.0