Mercurial > octave
changeset 22735:6f111a0f32c3
importdata.m: Fix failing BIST test (bug #49546).
* importdata.m: If line is prematurely short, use emptyvalue NA for missing
columns.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 07 Nov 2016 15:41:57 -0800 |
parents | c426d8ec521d |
children | 44d9d526d1e3 |
files | scripts/io/importdata.m |
diffstat | 1 files changed, 13 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/io/importdata.m Mon Nov 07 08:46:38 2016 -0800 +++ b/scripts/io/importdata.m Mon Nov 07 15:41:57 2016 -0800 @@ -243,10 +243,10 @@ ## Now, let the efficient built-in routine do the bulk of the work. if (delimiter == " ") output.data = dlmread (fname, "", header_rows, header_cols, - "emptyvalue", NaN); + "emptyvalue", NA); else output.data = dlmread (fname, delimiter, header_rows, header_cols, - "emptyvalue", NaN); + "emptyvalue", NA); endif ## Go back and correct any individual values that did not convert. @@ -267,11 +267,20 @@ fields = ostrsplit (row, delimiter); endif - text = fields(na_idx(ridx,:)); + missing_idx = na_idx(ridx,:); + if (! size_equal (missing_idx, fields)) + ## Fields completely missing at end of line. Replace with NA. + col = columns (fields); + output.data(ridx, (col+1):end) = NA; + missing_idx = missing_idx(1:col); + endif + text = fields(missing_idx); + text = text(! strcmpi (text, "NA")); # Remove valid "NA" entries if (! isempty (text)) - output.textdata(end+1:end+numel (text), 1) = text; + output.textdata = [output.textdata; text(:)]; endif + if (header_cols) output.rowheaders(end+1, :) = fields(1:header_cols); endif