Repository navigation
fix(data): GPX and workbook times past the microsecond are rounded and said, and whole-minute serials aren't called rounded #3498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a034665
ae9b9a5
a25e830
e4b4abe
87c9782
dca1e30
4cd351b
e7b22d6
ccff928
ac0e064
87ad077
42d6f62
bde41ad
d2de7f9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3617,6 +3617,17 @@ fn read_csv_with_budget(text: &str, name: &str, opts: &CsvOptions, budget: &mut | |
| read_csv_records(&mut rdr, name, opts, budget, None) | ||
| } | ||
|
|
||
| /// What a workbook knows of a sheet's columns beyond their text, by column ([`read_rows`]). | ||
| #[derive(Clone, Copy)] | ||
| pub(crate) struct Workbook<'a> { | ||
| /// The type its cells give a column, which overrides text inference. | ||
| pub types: &'a [Option<FieldType>], | ||
| /// Date cells of a day that never was (serial 60), read as empty. | ||
| pub phantom_dates: &'a [usize], | ||
| /// Serial date-times that held more than the microsecond, rounded to it. | ||
| pub rounded_dates: &'a [usize], | ||
| } | ||
|
|
||
| /// Rows of text cells under a header row (delimited text, a spreadsheet's sheet) as a dataset, as | ||
| /// [`read_csv_with`] describes; `malformed` rows were already passed over. A workbook gives its | ||
| /// cell types, which may override text inference by source column, and the dates it already read | ||
|
|
@@ -3627,9 +3638,9 @@ pub(crate) fn read_rows( | |
| malformed: usize, | ||
| name: &str, | ||
| opts: &CsvOptions, | ||
| workbook: Option<(&[Option<FieldType>], &[usize])>, | ||
| workbook: Option<Workbook<'_>>, | ||
| ) -> Result<(Dataset, ReadReport)> { | ||
| let types = workbook.map(|(types, _)| types); | ||
| let types = workbook.map(|wb| wb.types); | ||
| let position = |n: &str| headers.iter().position(|h| h.trim().eq_ignore_ascii_case(n)); | ||
| let named = |n: &Option<String>, what: &str| -> Result<Option<usize>> { | ||
| match n.as_deref().map(str::trim).filter(|n| !n.is_empty()) { | ||
|
|
@@ -3703,17 +3714,23 @@ pub(crate) fn read_rows( | |
| let gt = if xy.is_some() { GeometryType::Point } else { GeometryType::None }; | ||
| let mut ds = Dataset::new(name, gt, fields); | ||
| let mut srid: Option<u32> = None; | ||
| let (mut unread_dates, mut null_text, mut whitespace) = (Vec::new(), Vec::new(), Vec::new()); | ||
| for (k, &i) in columns.iter().enumerate() { | ||
| crate::source::unread_dates_by(&mut unread_dates, k, workbook.and_then(|(_, empty)| empty.get(i)).copied().unwrap_or(0)); | ||
| let (mut unread_dates, mut null_text, mut whitespace, mut rounded_dates) = (Vec::new(), Vec::new(), Vec::new(), Vec::new()); | ||
| for (k, (&i, field)) in columns.iter().zip(&ds.fields).enumerate() { | ||
| crate::source::unread_dates_by(&mut unread_dates, k, workbook.and_then(|wb| wb.phantom_dates.get(i)).copied().unwrap_or(0)); | ||
| // A workbook's serial date-times that held more than the microsecond, counted with the | ||
| // date-time text rounded below: one notice says both. A date field keeps only the day, | ||
| // so nothing of the microsecond is lost there. | ||
| if field.ty != FieldType::Date { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same silent day change as the FileGDB reader ( Category: bug |
||
| crate::source::unread_dates_by(&mut rounded_dates, k, workbook.and_then(|wb| wb.rounded_dates.get(i)).copied().unwrap_or(0)); | ||
| } | ||
| } | ||
| // The WKT column is the geometry, not a field: a workbook date there that never was is empty, | ||
| // so its row has no geometry, said here. | ||
| if let Some(w) = wkt { | ||
| let column = headers.get(w).map_or("", |h| h.trim()); | ||
| // The values read as empty, below the heading: each a value lost, and with it its row's | ||
| // geometry. | ||
| match workbook.and_then(|(_, empty)| empty.get(w)).copied().unwrap_or(0) { | ||
| match workbook.and_then(|wb| wb.phantom_dates.get(w)).copied().unwrap_or(0) { | ||
| 0 => {} | ||
| 1 => report.messages.push(crate::loss::Note::loss( | ||
| crate::loss::LossCode::DroppedValue, | ||
|
|
@@ -3771,7 +3788,15 @@ pub(crate) fn read_rows( | |
| if marker { | ||
| crate::source::null_text_at(&mut null_text, k); | ||
| } | ||
| let value = Value::parse_file(&text, f.ty); | ||
| // A date-time with digits past the microsecond (a workbook's ISO cell, as .NET | ||
| // writes them) is rounded to it and counted, not dropped. | ||
| let (value, rounded) = match f.ty { | ||
| FieldType::DateTime => Value::parse_stored_counted(&text, f.ty), | ||
| _ => (Value::parse_file(&text, f.ty), false), | ||
| }; | ||
| if rounded { | ||
| crate::source::unread_date(&mut rounded_dates, k); | ||
| } | ||
| if value.is_null() && f.ty != FieldType::Text && !text.is_empty() && text.trim().is_empty() { | ||
| crate::source::null_text_at(&mut whitespace, k); | ||
| } | ||
|
|
@@ -3880,6 +3905,8 @@ pub(crate) fn read_rows( | |
| } | ||
| report.unread_dates = crate::source::unread_dates_note(&ds.fields, &unread_dates); | ||
| report.messages.extend(report.unread_dates.clone()); | ||
| report.rounded_dates = crate::source::rounded_serials_note(&ds.fields, &rounded_dates); | ||
| report.messages.extend(report.rounded_dates.clone()); | ||
| report.messages.extend(crate::source::null_text_note(&ds.fields, &null_text)); | ||
| let total: usize = whitespace.iter().sum(); | ||
| if total > 0 { | ||
|
|
@@ -9965,6 +9992,18 @@ mod tests { | |
| assert_eq!(to_csv(&back).unwrap(), once, "export/import is stable"); | ||
| } | ||
|
|
||
| /// Delimited text never types a column as dates, so date-time text with digits past the | ||
| /// microsecond is kept as it is written, and nothing is said; six digits likewise. | ||
| #[test] | ||
| fn csv_date_time_text_is_kept_as_written() { | ||
| for time in ["2019-07-04T12:30:15.1234567Z", "2019-07-04T12:30:15.123456Z"] { | ||
| let (ds, report) = read_csv(&format!("when\n{time}\n"), "t").unwrap(); | ||
| assert_eq!(ds.fields[0].ty, FieldType::Text); | ||
| assert_eq!(ds.value(0, 0), &Value::Text(time.into())); | ||
| assert!(report.messages.is_empty() && report.rounded_dates.is_none(), "{report:?}"); | ||
| } | ||
| } | ||
|
|
||
| /// `<Null>` in a `.dbf` date column is counted once, as the marker, not also as a date that | ||
| /// isn't one, whole and streamed. | ||
| #[test] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a date-only field, a rounding that carries the value past midnight changes the day, and nothing says so.
rounded && !onlyleaves it uncounted, but the value is already the next day (Value::Date(t.date())at line 863). Example: the double one step below a whole day, such as just below 20001.0 (about 0.31 µs before midnight, in the 1944 to 1989 range where a double's step is under half a microsecond), rounds to midnight of 20001 and reads as the next day, with no notice. The workbook reader has the same exclusion (io.rs:3723). The test atfilegdb/tests.rs:979uses a time that doesn't cross midnight, so it doesn't cover this.Suggested fix: count a date-only rounding when the rounded day differs from the day the serial stores (compare
value's date with the date ofdays.floor()), and keep it silent otherwise. I worked this out from the f64 step sizes and did not run it, so confidence is medium.Category: bug