Repository navigation
feat(data): exports say what they cut, round, leave out or can't name with loss codes (#2371) #2973
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
ff60b18
09ae77b
aab4e37
daf9079
a2dd014
38ff798
733e674
acbdeb9
cf66086
02fd12e
be6f791
0fb88b3
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 | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1733,19 +1733,25 @@ impl DateLayout { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| /// Counts each representation change and names its fields for the user-facing export notice, | ||||||||||||||||||||||||
| /// each after `target: ` (nothing before it when `target` is empty: the caller adds the path). | ||||||||||||||||||||||||
| fn notes(&self, fields: &[Field], target: &str) -> Vec<String> { | ||||||||||||||||||||||||
| /// An offset left out is a value lost; ISO text keeps the value. | ||||||||||||||||||||||||
| fn notes(&self, fields: &[Field], target: &str) -> Vec<crate::loss::Note> { | ||||||||||||||||||||||||
| let target: String = target.chars().map(crate::io::dbf_notice_char).collect(); | ||||||||||||||||||||||||
| let target = if target.is_empty() { String::new() } else { format!("{target}: ") }; | ||||||||||||||||||||||||
| let mut notes = Vec::new(); | ||||||||||||||||||||||||
| let utc: Vec<usize> = self.offsets.iter().enumerate().map(|(k, &n)| if self.modes.get(k) == Some(&2) { n } else { 0 }).collect(); | ||||||||||||||||||||||||
| let text: Vec<usize> = self.counts.iter().enumerate().map(|(k, &n)| if self.modes.get(k) == Some(&3) { n } else { 0 }).collect(); | ||||||||||||||||||||||||
| for (counts, what) in [ | ||||||||||||||||||||||||
| (&utc, "date-times were written in UTC without their original offsets"), | ||||||||||||||||||||||||
| (&text, "date-times were written as ISO text because their column mixes zoned and unzoned values"), | ||||||||||||||||||||||||
| for (counts, what, lost) in [ | ||||||||||||||||||||||||
| (&utc, "date-times were written in UTC without their original offsets", true), | ||||||||||||||||||||||||
| (&text, "date-times were written as ISO text because their column mixes zoned and unzoned values", false), | ||||||||||||||||||||||||
| ] { | ||||||||||||||||||||||||
| let n: usize = counts.iter().sum(); | ||||||||||||||||||||||||
| if n > 0 { | ||||||||||||||||||||||||
| notes.push(format!("{target}{n} {what}, in {}", crate::io::named_fields(fields, counts))); | ||||||||||||||||||||||||
| let text = format!("{target}{n} {what}, in {}", crate::io::named_fields(fields, counts)); | ||||||||||||||||||||||||
| notes.push(if lost { | ||||||||||||||||||||||||
| crate::loss::Note::loss(crate::loss::LossCode::DroppedValue, text) | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| crate::loss::Note::plain(text) | ||||||||||||||||||||||||
|
Comment on lines
+1749
to
+1753
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. Nit: this
Suggested change
Confidence: high that it is harmless; this is a naming point only. Category: quality
Member
Author
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. Left for the release quality pass: it compiles and behaves as intended. |
||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| notes | ||||||||||||||||||||||||
|
|
@@ -1789,7 +1795,7 @@ fn unfit(ty: FieldType, value: &Value) -> bool { | |||||||||||||||||||||||
| /// The notice for values a GeoParquet export wrote as null because their column's type couldn't | ||||||||||||||||||||||||
| /// hold them, given the count per field (as `write_features` returns); `None` when there are | ||||||||||||||||||||||||
| /// none. Names the first five fields. | ||||||||||||||||||||||||
| pub fn unfit_note(fields: &[Field], counts: &[usize], target: &str) -> Option<String> { | ||||||||||||||||||||||||
| pub fn unfit_note(fields: &[Field], counts: &[usize], target: &str) -> Option<crate::loss::Note> { | ||||||||||||||||||||||||
| let total = counts.iter().fold(0usize, |a, n| a.saturating_add(*n)); | ||||||||||||||||||||||||
| if total == 0 { | ||||||||||||||||||||||||
| return None; | ||||||||||||||||||||||||
|
|
@@ -1804,12 +1810,15 @@ pub fn unfit_note(fields: &[Field], counts: &[usize], target: &str) -> Option<St | |||||||||||||||||||||||
| format!("{total} values couldn't be written as their columns' types and were") | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| let target: String = target.chars().map(crate::io::dbf_notice_char).collect(); | ||||||||||||||||||||||||
| Some(format!("{target}: {what} written as null, in {}{more}", list.join(", "))) | ||||||||||||||||||||||||
| Some(crate::loss::Note::loss( | ||||||||||||||||||||||||
| crate::loss::LossCode::DroppedValue, | ||||||||||||||||||||||||
| format!("{target}: {what} written as null, in {}{more}", list.join(", ")), | ||||||||||||||||||||||||
| )) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Export notices for the whole of `ds`: unfit values and timestamp representation changes. | ||||||||||||||||||||||||
| /// Cancellation omits notices; the following writer's check returns the cancellation error. | ||||||||||||||||||||||||
| pub fn values_note(ds: &crate::Dataset, target: &str) -> Option<String> { | ||||||||||||||||||||||||
| pub fn values_note(ds: &crate::Dataset, target: &str) -> Option<crate::loss::Note> { | ||||||||||||||||||||||||
| let mut counts = vec![0usize; ds.fields.len()]; | ||||||||||||||||||||||||
| let mut layout = DateLayout::default(); | ||||||||||||||||||||||||
| for chunk in ds.features.chunks(BATCH) { | ||||||||||||||||||||||||
|
|
@@ -1824,9 +1833,18 @@ pub fn values_note(ds: &crate::Dataset, target: &str) -> Option<String> { | |||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| let mut notes: Vec<String> = unfit_note(&ds.fields, &counts, target).into_iter().collect(); | ||||||||||||||||||||||||
| notes.extend(layout.notes(&ds.fields, target)); | ||||||||||||||||||||||||
| if notes.is_empty() { None } else { Some(notes.join("; ")) } | ||||||||||||||||||||||||
| // One notice: the values written as null, then how date-times are written; coded when either | ||||||||||||||||||||||||
| // loses a value. | ||||||||||||||||||||||||
| let said: Vec<crate::loss::Note> = | ||||||||||||||||||||||||
| unfit_note(&ds.fields, &counts, target).into_iter().chain(layout.notes(&ds.fields, target)).collect(); | ||||||||||||||||||||||||
| let loss = said.iter().find_map(|n| n.loss); | ||||||||||||||||||||||||
| (!said.is_empty()).then(|| { | ||||||||||||||||||||||||
| let text = said.iter().map(|n| n.text.as_str()).collect::<Vec<_>>().join("; "); | ||||||||||||||||||||||||
| match loss { | ||||||||||||||||||||||||
| Some(code) => crate::loss::Note::loss(code, text), | ||||||||||||||||||||||||
| None => crate::loss::Note::plain(text), | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /// Writes GeoParquet to `out`: the features `feed` hands to the function it is given, a run at | ||||||||||||||||||||||||
|
|
@@ -1844,7 +1862,7 @@ pub(crate) fn write_features<W: std::io::Write + Send>( | |||||||||||||||||||||||
| crs: Crs, | ||||||||||||||||||||||||
| out: W, | ||||||||||||||||||||||||
| feed: &mut dyn FnMut(&mut dyn FnMut(&[Feature]) -> Result<()>) -> Result<()>, | ||||||||||||||||||||||||
| ) -> Result<(W, Vec<usize>, Vec<String>)> { | ||||||||||||||||||||||||
| ) -> Result<(W, Vec<usize>, Vec<crate::loss::Note>)> { | ||||||||||||||||||||||||
| use parquet::basic::{Compression, Encoding, Repetition, ZstdLevel}; | ||||||||||||||||||||||||
| use parquet::data_type::{BoolType, ByteArray, ByteArrayType, DoubleType, Int32Type, Int64Type}; | ||||||||||||||||||||||||
| use parquet::file::metadata::KeyValue; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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.
This changed export path is coded, but the "rows couldn't be read" notice a few lines up (
lib.rs224-228, not in this diff) is still a plainsession.warn, so it carries no loss code. Python's loss warnings and--strictwon't see it. Every other path that says this notice now useswhole::unread_note, which carriesdropped.feature(whole.rsUnread::say,share.rswrite_layer,workflows.rsconvert, the ui-egui download). The PR says the codes reach "the rows a whole read can't read", and this path misses that.Suggested fix for 224-228, keeping the wording (
unread_notewrapsunread_notice, sotest_session.py's match still passes):report.skippedis ausize, andnameis defined on line 223. Confidence: high that the notice is uncoded.Category: bug
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.
Fixed in 38ff798: the Python GeoJSON export says its unread rows with
whole::unread_note,dropped.feature, in the same words.