Skip to content

Commit

Permalink
Merge pull request #175 from promised-ai/feature/added-not-in-date-error
Browse files Browse the repository at this point in the history
feat!: Added `DataParseError::DataFrameMissingColumn` variant for missing column in DataFrame when it is present in the metadata.
  • Loading branch information
schmidmt authored Feb 1, 2024
2 parents cad4cb4 + 05bd28f commit 965d522
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- `DataParseError::CodebookAndDataRowsMismatch` variant for when the number of rows in the codebook and the number of rows in the data do not match.
- `DataParseError::DataFrameMissingColumn` variant for when a column is in the codebook but not in the initial dataframe.

### Fixed
- Initializing an engine with a codebook that has a different number of rows than the data will result in an error instead of printing a bunch on nonsense.
Expand Down
6 changes: 5 additions & 1 deletion lace/src/data/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,11 @@ pub fn df_to_col_models<R: rand::Rng>(
.iter()
.enumerate()
.map(|(id, colmd)| {
let srs = srss[colmd.name.as_str()];
let srs = srss.get(colmd.name.as_str()).ok_or_else(|| {
DataParseError::DataFrameMissingColumn {
column: colmd.name.clone(),
}
})?;
let col_model = match &colmd.coltype {
ColType::Continuous { hyper, prior } => continuous_col_model(
id,
Expand Down
4 changes: 4 additions & 0 deletions lace/src/interface/engine/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ pub enum DataParseError {
n_codebook_rows: usize,
n_data_rows: usize,
},
#[error(
"The dataframe does not contain the column `{column}` listed in the codebook"
)]
DataFrameMissingColumn { column: String },
}

/// Errors that can arise when creating a new engine
Expand Down

0 comments on commit 965d522

Please sign in to comment.