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

Fixes #170 - remove dbg print instead of error #171

Merged
merged 1 commit into from
Jan 26, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- `DataParseError::CodebookAndDataRowsMismatch` variant for when the number of rows in the codebook and the number of rows in the data do not match.

### 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.

## [python-0.6.0] - 2024-01-23

### Added
Expand Down
17 changes: 7 additions & 10 deletions lace/src/data/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,14 @@ pub fn df_to_col_models<R: rand::Rng>(
})
.collect::<Result<_, DataParseError>>()?;

if col_models
.iter()
.any(|cm| cm.len() != codebook.row_names.len())
{
dbg!(
col_models.iter().map(|cm| cm.len()).collect::<Vec<_>>(),
codebook.row_names.len()
);
// FIXME!
// return Err(CsvParseError::CodebookAndDataRowMismatch);
let n_codebook_rows = codebook.row_names.len();
if let Some(cm) = col_models.iter().find(|cm| cm.len() != n_codebook_rows) {
return Err(DataParseError::CodebookAndDataRowsMismatch {
n_codebook_rows,
n_data_rows: cm.len(),
});
}

Ok((codebook, col_models))
}

Expand Down
10 changes: 8 additions & 2 deletions lace/src/interface/engine/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub enum DataParseError {
/// The supplied data source is not currently supported for this operation
#[error("Provided an unsupported data source")]
UnsupportedDataSource,
/// The user supplied column_metdata in the codebook but provided an empty
/// The user supplied column_metadata in the codebook but provided an empty
/// data source
#[error("non-empty column_metdata the codebook but empty DataSource")]
#[error("non-empty column_metadata the codebook but empty DataSource")]
ColumnMetadataSuppliedForEmptyData,
/// The user supplied row_names in the codebook but provided an empty
/// data source
Expand All @@ -36,6 +36,12 @@ pub enum DataParseError {
/// externally
#[error("Column `{col_name}` has type `{col_type}`, which is unsupported for external data sources")]
UnsupportedColumnType { col_name: String, col_type: String },
/// The codebook and the data have a different number of rows
#[error("The codebook contains {n_codebook_rows} rows, but the data contain {n_data_rows} rows")]
CodebookAndDataRowsMismatch {
n_codebook_rows: usize,
n_data_rows: usize,
},
}

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