use std::io;
use thiserror::Error;
use crate::cc::feature::FType;
use crate::codebook::CodebookError;
use crate::data::Category;
use crate::error::IndexError;
#[derive(Debug, Error)]
pub enum DataParseError {
#[error("io error: {0}")]
Io(#[from] io::Error),
#[error("Codebook error: {0}")]
Codebook(#[from] CodebookError),
#[error("Provided an unsupported data source")]
UnsupportedDataSource,
#[error("non-empty column_metadata the codebook but empty DataSource")]
ColumnMetadataSuppliedForEmptyData,
#[error("non-empty row_names the codebook but empty DataSource")]
RowNamesSuppliedForEmptyData,
#[error("No 'ID' column")]
NoIDColumn,
#[error("Multiple ID columns: {0:?}")]
MultipleIdColumns(Vec<String>),
#[error("Column `{col_name}` has type `{col_type}`, which is unsupported for external data sources")]
UnsupportedColumnType { col_name: String, col_type: String },
#[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,
},
#[error(
"The dataframe does not contain the column `{column}` listed in the codebook"
)]
DataFrameMissingColumn { column: String },
}
#[derive(Debug, Error)]
pub enum NewEngineError {
#[error("attempted to create an engine with zero states")]
ZeroStatesRequested,
#[error("data parse error: {0}")]
DataParseError(DataParseError),
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum InsertDataError {
#[error("No column metadata for column '{0}'")]
NoColumnMetadataForColumn(String),
#[error(
"the number of entries in col_metadata must match the number of new \
columns ({ncolmd} != {nnew})"
)]
WrongNumberOfColumnMetadataEntries {
ncolmd: usize,
nnew: usize,
},
#[error("The new column '{0}' was not found in the metadata")]
NewColumnNotInColumnMetadata(String),
#[error("Overwrite forbidden by requested mode")]
ModeForbidsOverwrite,
#[error("New rows forbidden by requested mode")]
ModeForbidsNewRows,
#[error("New columns forbidden by requested mode")]
ModeForbidsNewColumns,
#[error("New rows and columns forbidden by requested mode")]
ModeForbidsNewRowsOrColumns,
#[error(
"Categorical column support extension forbidden by requested mode"
)]
ModeForbidsCategoryExtension,
#[error("No Gaussian hyper prior for new column '{0}'")]
NoGaussianHyperForNewColumn(String),
#[error("No Poisson hyper prior for new column '{0}'")]
NoPoissonHyperForNewColumn(String),
#[error("No Categorical hyper prior for new column '{0}'")]
NoCategoricalHyperForNewColumn(String),
#[error(
"Provided a {ftype_req:?} data for '{col}' but '{col}' is {ftype:?}"
)]
DatumIncompatibleWithColumn {
col: String,
ftype_req: FType,
ftype: FType,
},
#[error("The row '{0}' is entirely empty")]
EmptyRow(String),
#[error(
"No insert col_metadata supplied for '{col_name}'. Categorical column \
'{col_name}' has a value_map, so to extend k from {n_cats} to \
{n_cats_req}, a value_map must be supplied in col_metadata to add the \
new values and maintain a valid codebook"
)]
NoNewValueMapForCategoricalExtension {
n_cats: usize,
n_cats_req: usize,
col_name: String,
},
#[error(
"Passed {ftype_md:?} ColType through col_metadata for column \
{col_name}, which is {ftype:?}"
)]
WrongMetadataColType {
col_name: String,
ftype: FType,
ftype_md: FType,
},
#[error(
"The value_map supplied for column {col_name} does not contain the \
correct entries to support the requested operation."
)]
IncompleteValueMap { col_name: String },
#[error(
"Attempted to insert a non-finite value ({value}) into column \
`{col}`"
)]
NonFiniteContinuousValue { col: String, value: f64 },
#[error("Row index error: {0}")]
RowIndex(IndexError),
#[error("Column index error: {0}")]
ColumnIndex(IndexError),
#[error("How can you extract what is unreachable?")]
Unreachable,
#[error(
"The column with usize index '{0}' appears to be new, but new columns \
must be given string names"
)]
IntegerIndexNewColumn(usize),
#[error(
"The row with usize index '{0}' appears to be new, but new rows \
must be given string names"
)]
IntegerIndexNewRow(usize),
#[error("Tried to extend to support of boolen column '{0}'")]
ExtendBooleanColumn(String),
#[error("Could not find value in categorical value map")]
CategoryNotInValueMap(Category),
#[error("Attempted to add a category '{1}' to a column of type '{0}' for column '{2}'")]
WrongCategoryAndType(String, String, String),
}
#[derive(Debug, Clone, PartialEq, Error)]
pub enum RemoveDataError {
#[error("Index error: {0}")]
Index(#[from] IndexError),
}