Skip to content
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

feat!: Added DataParseError::DataFrameMissingColumn variant for missing column in DataFrame when it is present in the metadata. #175

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading