Skip to content

Commit bef4bb6

Browse files
authored
Allow empty provenance records. (#151)
Closes #150
1 parent 86df702 commit bef4bb6

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

src/provenance.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,7 @@ impl<'a> ProvenanceTable<'a> {
242242
self.table_.record_length
243243
) {
244244
Ok(Some(string)) => Ok(string),
245-
Ok(None) => Err(crate::TskitError::ValueError {
246-
got: String::from("None"),
247-
expected: String::from("String"),
248-
}),
245+
Ok(None) => Ok(String::from("")),
249246
Err(e) => Err(e),
250247
}
251248
}
@@ -277,27 +274,27 @@ impl<'a> ProvenanceTable<'a> {
277274
}
278275

279276
#[cfg(test)]
280-
mod test_trigger_provenance_errors {
277+
mod test_provenance_tables {
281278
use super::*;
282279
use crate::test_fixtures::make_empty_table_collection;
283280
use Provenance;
284281

285282
#[test]
286-
#[should_panic]
287283
fn test_empty_record_string() {
288-
//TODO: decide if we like this behavior:
289-
//See GitHub issue 150 -- this behavior should change.
284+
// check for tables...
290285
let mut tables = make_empty_table_collection(1.0);
291-
let row_id = tables.add_provenance(&String::from("")).unwrap();
286+
let s = String::from("");
287+
let row_id = tables.add_provenance(&s).unwrap();
292288
let _ = tables.provenances().row(row_id).unwrap();
293-
}
294-
}
295289

296-
#[cfg(test)]
297-
mod test_provenance_tables {
298-
use super::*;
299-
use crate::test_fixtures::make_empty_table_collection;
300-
use Provenance;
290+
// and for tree sequences...
291+
tables.build_index().unwrap();
292+
let mut ts = tables
293+
.tree_sequence(crate::TreeSequenceFlags::default())
294+
.unwrap();
295+
let row_id = ts.add_provenance(&s).unwrap();
296+
let _ = ts.provenances().row(row_id).unwrap();
297+
}
301298

302299
#[test]
303300
fn test_add_rows() {

src/table_collection.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,12 +725,6 @@ impl crate::traits::NodeListGenerator for TableCollection {}
725725
#[cfg(any(doc, feature = "provenance"))]
726726
impl crate::provenance::Provenance for TableCollection {
727727
fn add_provenance(&mut self, record: &str) -> Result<crate::ProvenanceId, TskitError> {
728-
if record.is_empty() {
729-
return Err(TskitError::ValueError {
730-
got: String::from("empty string slice"),
731-
expected: String::from("non-empty string slice"),
732-
});
733-
}
734728
let timestamp = chrono::prelude::Local::now().to_rfc3339();
735729
let rv = unsafe {
736730
ll_bindings::tsk_provenance_table_add_row(

src/trees.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,12 +1138,6 @@ impl crate::traits::NodeListGenerator for TreeSequence {}
11381138
#[cfg(any(doc, feature = "provenance"))]
11391139
impl crate::provenance::Provenance for TreeSequence {
11401140
fn add_provenance(&mut self, record: &str) -> Result<crate::ProvenanceId, TskitError> {
1141-
if record.is_empty() {
1142-
return Err(TskitError::ValueError {
1143-
got: String::from("empty string slice"),
1144-
expected: String::from("non-empty string slice"),
1145-
});
1146-
}
11471141
let timestamp = chrono::prelude::Local::now().to_rfc3339();
11481142
let rv = unsafe {
11491143
ll_bindings::tsk_provenance_table_add_row(

0 commit comments

Comments
 (0)