Skip to content

fread fill=true and sep= provided could still read as 1-column - #2755

Merged
mattdowle merged 11 commits into
masterfrom
fread_sep_ignored
Apr 19, 2018
Merged

mattdowle merged 11 commits into
masterfrom
fread_sep_ignored

Conversation

@mattdowle

@mattdowle mattdowle commented Apr 17, 2018 •

Copy link
Copy Markdown
Member

Closes #2666

The root cause was the fallback to single-column input that happened in all cases.

  • reorganized sep/quoteRule detection into different sections depending on whether fill=true/false and whether ncol==1 or >1. Different rules in different situations should be easier now. The numLines and numFields VLAs are no longer needed and there isn't a second step to find the first line again (to avoid inconsistencies there).
  • added warning when healing quoteRule is selected in jump 0 sample. (There was already a warning when healing quoteRule is chosen out-of-sample.) Any invalid files that are auto-healed should produce warning.
  • fill=true now uses the longest line from the jump 0 sample (which will most often be the column names on row 1), so long as the first row has more than one field with that sep/quoteRule. As before, no auto-skip when fill=true.

@codecov-io

codecov-io commented Apr 17, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #2755 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2755      +/-   ##
==========================================
+ Coverage   93.45%   93.46%   +0.01%     
==========================================
  Files          61       61              
  Lines       12323    12358      +35     
==========================================
+ Hits        11516    11551      +35     
  Misses        807      807
Impacted Files Coverage Δ
R/test.data.table.R 100% <100%> (ø) ⬆️
src/fread.c 98.03% <100%> (+0.05%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d0de24...7704ec6. Read the comment docs.

@mattdowle mattdowle added this to the v1.10.6 milestone Apr 17, 2018
@mattdowle
mattdowle requested a review from st-pasha April 17, 2018 01:13
@mattdowle mattdowle changed the title Specifying sep could be ignored fread fill=true and sep= provided could still read as 1-column Apr 17, 2018

@st-pasha st-pasha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that now quote rules 2 and 3 are considered "improper" , and a warning will be issued whenever one of these rules is employed.

This is something we should be more upfront with in PR description, and in the Changelog. Note that this could be a breaking change for people who run fread under "warnings are errors" mode. Though I agree that QR=2 feels kinda like a bandaid, I'm not so sure about QR=3. After all, if a user chooses an uncommon sep (e.g. \x01), then it may be perfectly normal not to quote any fields regardless of whether they contain any quote characters or not.

Also I couldn't understand what does "self healing quote rule" mean, which was mentioned several times in comments.

Overall, I liked the reorg of the sep-detection logic: having fill=True case considered separately makes things less convoluted and more robust.

Comment thread inst/tests/tests.Rraw Outdated
@@ -3959,11 +3959,14 @@ test(1215,
data.table(N_ID=175931L, VISIT_DATE="2013-03-08T23:40:30", REQ_URL='http://aaa.com/rest/api2.do?api=getSetMobileSession&data={"imei":"60893ZTE-CN13cd","appkey":"android_client","content":"Z0JiRA0qPFtWM3BYVltmcx5MWF9ZS0YLdW1ydXoqPycuJS8idXdlY3R0TGBtU', REQType=2L)
)
test(1216.1, fread('A,B,C\n1.2,Foo"Bar,"a"b\"c"d"\nfo"o,bar,"b,az""\n'),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks confusing: do you mean to have
'A,B,C\n1.2,Foo"Bar,"a"b"c"d"\nfo"o,bar,"b,az""\n'
or
'A,B,C\n1.2,Foo"Bar,"a"b\\"c"d"\nfo"o,bar,"b,az""\n' ?

@mattdowle mattdowle Apr 17, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'm not sure what is meant by that extra \ in that test before the \"c. It's superfluous since opening the string ' automatically escapes any " inside the string. I checked that as follows :

> identical('A,B,C\n1.2,Foo"Bar,"a"b"c"d"\nfo"o,bar,"b,az""\n',
+           'A,B,C\n1.2,Foo"Bar,"a"b\"c"d"\nfo"o,bar,"b,az""\n')
[1] TRUE

So out of the two choices you present, the first one is what it does. Maybe the second one is what was intended.

I'll add them all in, with a comment alongside.

@mattdowle

mattdowle commented Apr 17, 2018 •

Copy link
Copy Markdown
Member Author

It seems that now quote rules 2 and 3 are considered "improper" , and a warning will be issued whenever one of these rules is employed.

Yes. Other csv readers halt with 'file invalid' message. We should at least have a warning.

This is something we should be more upfront with in PR description.

It is mentioned in this PR's description, point 2. Feel free to edit better wording in there as I'm not sure what you mean.

and in the Changelog

Good point. Will add something to NEWS.

Also I couldn't understand what does "self healing quote rule" mean, which was mentioned several times in comments.

"Self-healing" is meant to convey "automatic-fixing". The idea is that quote rules 2 and 3 deal with invalid files. Without them, the file would fail to read due to the otherwise invalid quote.

Note that this could be a breaking change for people who run fread under "warnings are errors" mode.

Yes and that's better behaviour. Such users will want to know that fread thinks their file is invalid and an attempt to fix it has been made by data.table. They will likely want to only use fully correct and fully valid formats, so they want fread to warn about any little thing that might be wrong.

Note there is no way to control quote rule currently. Due in part not being sure what its parameter values should take, since the quote rule is still bedding down. It could be "auto.warn" (default), "auto.silent", or a specific rule by number or name. Currently user can turn off the new warning with suppressWarnings() but that also turns off all warnings from that fread call too. I suggest I create a new feature request for quoteRule= to be implemented in future, otherwise we'll never get anything out the door. [Done - #2768]

After all, if a user chooses an uncommon sep (e.g. \x01), then it may be perfectly normal not to quote any fields regardless of whether they contain any quote characters or not.

Yes and that's why quote rule 3 exists. But that is unusual and should be warned about because it's more likely something is wrong in a regular comma-separated-file. If file is using unusual sep for that reason without any quoted fields, but where the field does contain quotes, the warning now suggests to set quote="". This turns off the warning and reads the file cleanly and correctly. Readers of the code containing that fread call would then see immediately that an unquoted file was being read. (I previously suggested leaving this to later, but as it turned out, quote="" already worked -- test 1906 added).

@mattdowle

Copy link
Copy Markdown
Member Author

@st-pasha Have addressed your comments and this PR is complete I hope. Please re-review.

@mattdowle
mattdowle merged commit c44aeb3 into master Apr 19, 2018
@mattdowle
mattdowle deleted the fread_sep_ignored branch April 19, 2018 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants