update miette and switch to GenericErrors (#5222)

This commit is contained in:
Kat Marchán
2022-04-18 05:34:10 -07:00
committed by GitHub
parent cf65f77b02
commit 1314a87cb0
141 changed files with 1569 additions and 689 deletions

View File

@ -43,17 +43,21 @@ impl Operation {
"last" => Ok(Operation::Last),
"nunique" => Ok(Operation::Nunique),
"quantile" => match quantile {
None => Err(ShellError::SpannedLabeledError(
None => Err(ShellError::GenericError(
"Quantile value not fount".into(),
"Quantile operation requires quantile value".into(),
name.span,
Some(name.span),
None,
Vec::new(),
)),
Some(value) => {
if (value.item < 0.0) | (value.item > 1.0) {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Inappropriate quantile".into(),
"Quantile value should be between 0.0 and 1.0".into(),
value.span,
Some(value.span),
None,
Vec::new(),
))
} else {
Ok(Operation::Quantile(value.item))
@ -82,11 +86,12 @@ impl Operation {
match did_you_mean(&possibilities, selection) {
Some(suggestion) => Err(ShellError::DidYouMean(suggestion, name.span)),
None => Err(ShellError::SpannedLabeledErrorHelp(
None => Err(ShellError::GenericError(
"Operation not fount".into(),
"Operation does not exist".into(),
name.span,
"Perhaps you want: mean, sum, min, max, first, last, nunique, quantile, median, var, std, or count".into(),
Some(name.span),
Some("Perhaps you want: mean, sum, min, max, first, last, nunique, quantile, median, var, std, or count".into()),
Vec::new(),
))
}
}
@ -239,17 +244,21 @@ fn command(
None,
))
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect datatype".into(),
"no groupby or dataframe found in input stream".into(),
call.head,
Some(call.head),
None,
Vec::new(),
)),
}
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect datatype".into(),
"no groupby or dataframe found in input stream".into(),
call.head,
Some(call.head),
None,
Vec::new(),
)),
}
}
@ -283,7 +292,13 @@ fn perform_groupby_aggregation(
_ => operation_span,
};
ShellError::SpannedLabeledError("Error calculating aggregation".into(), e.to_string(), span)
ShellError::GenericError(
"Error calculating aggregation".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
if !explicit {
@ -335,10 +350,12 @@ fn perform_dataframe_aggregation(
Operation::Quantile(quantile) => dataframe
.quantile(quantile, QuantileInterpolOptions::default())
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error calculating quantile".into(),
e.to_string(),
operation_span,
Some(operation_span),
None,
Vec::new(),
)
}),
Operation::Median => Ok(dataframe.median()),
@ -358,11 +375,15 @@ fn perform_dataframe_aggregation(
match did_you_mean(&possibilities, operation.to_str()) {
Some(suggestion) => Err(ShellError::DidYouMean(suggestion, operation_span)),
None => Err(ShellError::SpannedLabeledErrorHelp(
None => Err(ShellError::GenericError(
"Operation not fount".into(),
"Operation does not exist".into(),
operation_span,
"Perhaps you want: mean, sum, min, max, quantile, median, var, or std".into(),
Some(operation_span),
Some(
"Perhaps you want: mean, sum, min, max, quantile, median, var, or std"
.into(),
),
Vec::new(),
)),
}
}

View File

@ -62,7 +62,13 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let res = df.as_ref().column(&column.item).map_err(|e| {
ShellError::SpannedLabeledError("Error selecting column".into(), e.to_string(), column.span)
ShellError::GenericError(
"Error selecting column".into(),
e.to_string(),
Some(column.span),
None,
Vec::new(),
)
})?;
NuDataFrame::try_from_series(vec![res.clone()], call.head)

View File

@ -121,18 +121,22 @@ fn command(
if (&0.0..=&1.0).contains(&val) {
Ok(*val)
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Incorrect value for quantile".to_string(),
"value should be between 0 and 1".to_string(),
*span,
Some(*span),
None,
Vec::new(),
))
}
}
_ => match value.span() {
Ok(span) => Err(ShellError::SpannedLabeledError(
Ok(span) => Err(ShellError::GenericError(
"Incorrect value for quantile".to_string(),
"value should be a float".to_string(),
span,
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(e),
},
@ -242,7 +246,13 @@ fn command(
DataFrame::new(res)
.map_err(|e| {
ShellError::SpannedLabeledError("Dataframe Error".into(), e.to_string(), call.head)
ShellError::GenericError(
"Dataframe Error".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -66,18 +66,22 @@ fn command(
let new_df = col_string
.get(0)
.ok_or_else(|| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Empty names list".into(),
"No column names where found".into(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})
.and_then(|col| {
df.as_ref().drop(&col.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error dropping column".into(),
e.to_string(),
col.span,
Some(col.span),
None,
Vec::new(),
)
})
})?;
@ -89,10 +93,12 @@ fn command(
.skip(1)
.try_fold(new_df, |new_df, col| {
new_df.drop(&col.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error dropping column".into(),
e.to_string(),
col.span,
Some(col.span),
None,
Vec::new(),
)
})
})

View File

@ -97,10 +97,12 @@ fn command(
df.as_ref()
.distinct(subset_slice, keep_strategy)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error dropping duplicates".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -112,7 +112,13 @@ fn command(
df.as_ref()
.drop_nulls(subset_slice)
.map_err(|e| {
ShellError::SpannedLabeledError("Error dropping nulls".into(), e.to_string(), col_span)
ShellError::GenericError(
"Error dropping nulls".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -115,11 +115,12 @@ fn command(
df.as_ref()
.to_dummies()
.map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error calculating dummies".into(),
e.to_string(),
call.head,
"The only allowed column types for dummies are String or Int".into(),
Some(call.head),
Some("The only allowed column types for dummies are String or Int".into()),
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -63,11 +63,12 @@ fn command(
let mask_span = mask_value.span()?;
let mask = NuDataFrame::try_from_value(mask_value)?.as_series(mask_span)?;
let mask = mask.bool().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to bool".into(),
e.to_string(),
mask_span,
"Perhaps you want to use a series with booleans as mask".into(),
Some(mask_span),
Some("Perhaps you want to use a series with booleans as mask".into()),
Vec::new(),
)
})?;
@ -76,11 +77,12 @@ fn command(
df.as_ref()
.filter(mask)
.map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error calculating dummies".into(),
e.to_string(),
call.head,
"The only allowed column types for dummies are String or Int".into(),
Some(call.head),
Some("The only allowed column types for dummies are String or Int".into()),
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -67,10 +67,12 @@ fn command(
df.as_ref()
.select(&col_string)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -61,7 +61,13 @@ fn command(
// dataframe. Once it has been done these values can be stored
// in a NuGroupBy
let groupby = df.as_ref().groupby(&col_string).map_err(|e| {
ShellError::SpannedLabeledError("Error creating groupby".into(), e.to_string(), col_span)
ShellError::GenericError(
"Error creating groupby".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
})?;
let groups = groupby.get_groups();

View File

@ -116,11 +116,12 @@ fn command(
"outer" => JoinType::Outer,
"left" => JoinType::Left,
_ => {
return Err(ShellError::SpannedLabeledErrorHelp(
return Err(ShellError::GenericError(
"Incorrect join type".into(),
"Invalid join type".into(),
val.span,
"Options: inner, outer or left".into(),
Some(val.span),
Some("Options: inner, outer or left".into()),
Vec::new(),
))
}
},
@ -150,10 +151,12 @@ fn command(
suffix,
)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error joining dataframes".into(),
e.to_string(),
l_col_span,
Some(l_col_span),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
@ -168,45 +171,51 @@ fn check_column_datatypes<T: AsRef<str>>(
r_col_span: Span,
) -> Result<(), ShellError> {
if l_cols.len() != r_cols.len() {
return Err(ShellError::SpannedLabeledErrorHelp(
return Err(ShellError::GenericError(
"Mismatched number of column names".into(),
format!(
"found {} left names vs {} right names",
l_cols.len(),
r_cols.len()
),
l_col_span,
"perhaps you need to change the number of columns to join".into(),
Some(l_col_span),
Some("perhaps you need to change the number of columns to join".into()),
Vec::new(),
));
}
for (l, r) in l_cols.iter().zip(r_cols) {
let l_series = df_l.column(l.as_ref()).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error selecting the columns".into(),
e.to_string(),
l_col_span,
Some(l_col_span),
None,
Vec::new(),
)
})?;
let r_series = df_r.column(r.as_ref()).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error selecting the columns".into(),
e.to_string(),
r_col_span,
Some(r_col_span),
None,
Vec::new(),
)
})?;
if l_series.dtype() != r_series.dtype() {
return Err(ShellError::SpannedLabeledErrorHelp(
return Err(ShellError::GenericError(
"Mismatched datatypes".into(),
format!(
"left column type '{}' doesn't match '{}' right column match",
l_series.dtype(),
r_series.dtype()
),
l_col_span,
"perhaps you need to select other column to match".into(),
Some(l_col_span),
Some("perhaps you need to select other column to match".into()),
Vec::new(),
));
}
}

View File

@ -148,29 +148,35 @@ fn command(
.as_ref()
.melt(&id_col_string, &val_col_string)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error calculating melt".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
if let Some(name) = &variable_name {
res.rename("variable", &name.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error renaming column".into(),
e.to_string(),
name.span,
Some(name.span),
None,
Vec::new(),
)
})?;
}
if let Some(name) = &value_name {
res.rename("value", &name.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error renaming column".into(),
e.to_string(),
name.span,
Some(name.span),
None,
Vec::new(),
)
})?;
}
@ -187,10 +193,12 @@ fn check_column_datatypes<T: AsRef<str>>(
col_span: Span,
) -> Result<(), ShellError> {
if cols.is_empty() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Merge error".into(),
"empty column list".into(),
col_span,
Some(col_span),
None,
Vec::new(),
));
}
@ -198,31 +206,36 @@ fn check_column_datatypes<T: AsRef<str>>(
if cols.len() > 1 {
for w in cols.windows(2) {
let l_series = df.column(w[0].as_ref()).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})?;
let r_series = df.column(w[1].as_ref()).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})?;
if l_series.dtype() != r_series.dtype() {
return Err(ShellError::SpannedLabeledErrorHelp(
return Err(ShellError::GenericError(
"Merge error".into(),
"found different column types in list".into(),
col_span,
format!(
Some(col_span),
Some(format!(
"datatypes {} and {} are incompatible",
l_series.dtype(),
r_series.dtype()
),
)),
Vec::new(),
));
}
}

View File

@ -115,7 +115,13 @@ fn from_parquet(
let columns: Option<Vec<String>> = call.get_flag(engine_state, stack, "columns")?;
let r = File::open(&file.item).map_err(|e| {
ShellError::SpannedLabeledError("Error opening file".into(), e.to_string(), file.span)
ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
})?;
let reader = ParquetReader::new(r);
@ -125,10 +131,12 @@ fn from_parquet(
};
reader.finish().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Parquet reader error".into(),
format!("{:?}", e),
call.head,
Some(call.head),
None,
Vec::new(),
)
})
}
@ -140,14 +148,26 @@ fn from_json(
) -> Result<polars::prelude::DataFrame, ShellError> {
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let mut file = File::open(&file.item).map_err(|e| {
ShellError::SpannedLabeledError("Error opening file".into(), e.to_string(), file.span)
ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
})?;
let buf_reader = BufReader::new(&mut file);
let reader = JsonReader::new(buf_reader);
reader.finish().map_err(|e| {
ShellError::SpannedLabeledError("Json reader error".into(), format!("{:?}", e), call.head)
ShellError::GenericError(
"Json reader error".into(),
format!("{:?}", e),
Some(call.head),
None,
Vec::new(),
)
})
}
@ -165,10 +185,12 @@ fn from_csv(
let csv_reader = CsvReader::from_path(&file.item)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating CSV reader".into(),
e.to_string(),
file.span,
Some(file.span),
None,
Vec::new(),
)
})?
.with_encoding(CsvEncoding::LossyUtf8);
@ -177,10 +199,12 @@ fn from_csv(
None => csv_reader,
Some(d) => {
if d.item.len() != 1 {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Incorrect delimiter".into(),
"Delimiter has to be one character".into(),
d.span,
Some(d.span),
None,
Vec::new(),
));
} else {
let delimiter = match d.item.chars().next() {
@ -210,10 +234,12 @@ fn from_csv(
};
csv_reader.finish().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Parquet reader error".into(),
format!("{:?}", e),
call.head,
Some(call.head),
None,
Vec::new(),
)
})
}

View File

@ -28,11 +28,12 @@ impl Operation {
"max" => Ok(Operation::Max),
"mean" => Ok(Operation::Mean),
"median" => Ok(Operation::Median),
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Operation not fount".into(),
"Operation does not exist for pivot".into(),
name.span,
"Options: first, sum, min, max, mean, median".into(),
Some(name.span),
Some("Options: first, sum, min, max, mean, median".into()),
Vec::new(),
)),
}
}
@ -116,7 +117,13 @@ fn command(
Operation::Median => pivot.median(),
}
.map_err(|e| {
ShellError::SpannedLabeledError("Error creating pivot".into(), e.to_string(), call.head)
ShellError::GenericError(
"Error creating pivot".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}
@ -126,7 +133,13 @@ fn check_pivot_column(
col: &Spanned<String>,
) -> Result<(), ShellError> {
let series = df.column(&col.item).map_err(|e| {
ShellError::SpannedLabeledError("Column not found".into(), e.to_string(), col.span)
ShellError::GenericError(
"Column not found".into(),
e.to_string(),
Some(col.span),
None,
Vec::new(),
)
})?;
match series.dtype() {
@ -139,10 +152,12 @@ fn check_pivot_column(
| DataType::Int32
| DataType::Int64
| DataType::Utf8 => Ok(()),
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Pivot error".into(),
format!("Unsupported datatype {}", series.dtype()),
col.span,
Some(col.span),
None,
Vec::new(),
)),
}
}
@ -152,7 +167,13 @@ fn check_value_column(
col: &Spanned<String>,
) -> Result<(), ShellError> {
let series = df.column(&col.item).map_err(|e| {
ShellError::SpannedLabeledError("Column not found".into(), e.to_string(), col.span)
ShellError::GenericError(
"Column not found".into(),
e.to_string(),
Some(col.span),
None,
Vec::new(),
)
})?;
match series.dtype() {
@ -166,10 +187,12 @@ fn check_value_column(
| DataType::Int64
| DataType::Float32
| DataType::Float64 => Ok(()),
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Pivot error".into(),
format!("Unsupported datatype {}", series.dtype()),
col.span,
Some(col.span),
None,
Vec::new(),
)),
}
}

View File

@ -72,7 +72,13 @@ fn command(
df.as_mut()
.rename(&from, &to)
.map_err(|e| {
ShellError::SpannedLabeledError("Error renaming".into(), e.to_string(), call.head)
ShellError::GenericError(
"Error renaming".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})
.map(|df| {
PipelineData::Value(

View File

@ -77,29 +77,36 @@ fn command(
match (rows, fraction) {
(Some(rows), None) => df.as_ref().sample_n(rows.item, replace, 0).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating sample".into(),
e.to_string(),
rows.span,
Some(rows.span),
None,
Vec::new(),
)
}),
(None, Some(frac)) => df.as_ref().sample_frac(frac.item, replace, 0).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating sample".into(),
e.to_string(),
frac.span,
Some(frac.span),
None,
Vec::new(),
)
}),
(Some(_), Some(_)) => Err(ShellError::SpannedLabeledError(
(Some(_), Some(_)) => Err(ShellError::GenericError(
"Incompatible flags".into(),
"Only one selection criterion allowed".into(),
call.head,
Some(call.head),
None,
Vec::new(),
)),
(None, None) => Err(ShellError::SpannedLabeledErrorHelp(
(None, None) => Err(ShellError::GenericError(
"No selection".into(),
"No selection criterion was found".into(),
call.head,
"Perhaps you want to use the flag -n or -f".into(),
Some(call.head),
Some("Perhaps you want to use the flag -n or -f".into()),
Vec::new(),
)),
}
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -95,10 +95,12 @@ fn command(
df.as_ref()
.sort(columns, reverse)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error sorting dataframe".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
@ -111,20 +113,24 @@ fn command(
df.as_ref()
.sort(&col_string, reverse)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error sorting dataframe".into(),
e.to_string(),
col_span,
Some(col_span),
None,
Vec::new(),
)
})
.map(|df| {
PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None)
})
} else {
Err(ShellError::SpannedLabeledError(
Err(ShellError::GenericError(
"Missing columns".into(),
"missing column name to perform sort".into(),
call.head,
Some(call.head),
None,
Vec::new(),
))
}
}

View File

@ -95,26 +95,31 @@ fn command(
let casted = match index.dtype() {
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => {
index.cast(&DataType::UInt32).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting index list".into(),
e.to_string(),
index_span,
Some(index_span),
None,
Vec::new(),
)
})
}
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
"Series with incorrect type".into(),
call.head,
"Consider using a Series with type int type".into(),
Some(call.head),
Some("Consider using a Series with type int type".into()),
Vec::new(),
)),
}?;
let indices = casted.u32().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting index list".into(),
e.to_string(),
index_span,
Some(index_span),
None,
Vec::new(),
)
})?;
@ -122,10 +127,12 @@ fn command(
df.as_ref()
.take(indices)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error taking values".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))

View File

@ -74,10 +74,12 @@ fn command(
let mut df = NuDataFrame::try_from_pipeline(input, call.head)?;
let mut file = File::create(&file_name.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error with file name".into(),
e.to_string(),
file_name.span,
Some(file_name.span),
None,
Vec::new(),
)
})?;
@ -93,10 +95,12 @@ fn command(
None => writer,
Some(d) => {
if d.item.len() != 1 {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Incorrect delimiter".into(),
"Delimiter has to be one char".into(),
d.span,
Some(d.span),
None,
Vec::new(),
));
} else {
let delimiter = match d.item.chars().next() {
@ -110,10 +114,12 @@ fn command(
};
writer.finish(df.as_mut()).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error writing to file".into(),
e.to_string(),
file_name.span,
Some(file_name.span),
None,
Vec::new(),
)
})?;

View File

@ -58,15 +58,23 @@ fn command(
let mut df = NuDataFrame::try_from_pipeline(input, call.head)?;
let file = File::create(&file_name.item).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error with file name".into(),
e.to_string(),
file_name.span,
Some(file_name.span),
None,
Vec::new(),
)
})?;
ParquetWriter::new(file).finish(df.as_mut()).map_err(|e| {
ShellError::SpannedLabeledError("Error saving file".into(), e.to_string(), file_name.span)
ShellError::GenericError(
"Error saving file".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
})?;
let file_value = Value::String {

View File

@ -83,10 +83,12 @@ fn command(
df.as_mut()
.with_column(series)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error adding column to dataframe".into(),
e.to_string(),
other_span,
Some(other_span),
None,
Vec::new(),
)
})
.map(|df| {

View File

@ -74,10 +74,12 @@ fn command(
let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error converting to bool".into(),
"all-false only works with series of type bool".into(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -74,10 +74,12 @@ fn command(
let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error converting to bool".into(),
"all-false only works with series of type bool".into(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -20,11 +20,12 @@ impl CumType {
"min" => Ok(Self::Min),
"max" => Ok(Self::Max),
"sum" => Ok(Self::Sum),
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Wrong operation".into(),
"Operation not valid for cumulative".into(),
span,
"Allowed values: max, min, sum".into(),
Some(span),
Some("Allowed values: max, min, sum".into()),
Vec::new(),
)),
}
}
@ -102,10 +103,12 @@ fn command(
let series = df.as_series(call.head)?;
if let DataType::Object(_) = series.dtype() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Found object series".into(),
"Series of type object cannot be used for cumulative operation".into(),
call.head,
Some(call.head),
None,
Vec::new(),
));
}

View File

@ -65,7 +65,13 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to string".into(), e.to_string(), call.head)
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
let res = if not_exact {
@ -76,10 +82,12 @@ fn command(
let mut res = res
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating datetime".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?
.into_series();

View File

@ -98,7 +98,13 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to string".into(), e.to_string(), call.head)
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
let res = if not_exact {
@ -109,10 +115,12 @@ fn command(
let mut res = res
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating datetime".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?
.into_series();

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -59,10 +59,12 @@ fn command(
let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error converting to bool".into(),
"all-false only works with series of type bool".into(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -61,10 +61,12 @@ fn command(
.as_series(call.head)?
.arg_unique()
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error extracting unique values".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?
.into_series();

View File

@ -84,28 +84,33 @@ fn command(
let casted = match indices.dtype() {
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => {
indices.as_ref().cast(&DataType::UInt32).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting indices".into(),
e.to_string(),
indices_span,
Some(indices_span),
None,
Vec::new(),
)
})
}
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
"Series with incorrect type".into(),
indices_span,
"Consider using a Series with type int type".into(),
Some(indices_span),
Some("Consider using a Series with type int type".into()),
Vec::new(),
)),
}?;
let indices = casted
.u32()
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting indices".into(),
e.to_string(),
indices_span,
Some(indices_span),
None,
Vec::new(),
)
})?
.into_iter()
@ -117,42 +122,70 @@ fn command(
let res = match value {
Value::Int { val, span } => {
let chunked = series.i64().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to i64".into(), e.to_string(), span)
ShellError::GenericError(
"Error casting to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked.set_at_idx(indices, Some(val)).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span)
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
Value::Float { val, span } => {
let chunked = series.as_ref().f64().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to f64".into(), e.to_string(), span)
ShellError::GenericError(
"Error casting to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked.set_at_idx(indices, Some(val)).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span)
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
Value::String { val, span } => {
let chunked = series.as_ref().utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked
.set_at_idx(indices, Some(val.as_ref()))
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)
})?;
@ -161,13 +194,15 @@ fn command(
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect value type".into(),
format!(
"this value cannot be set in a series of type '{}'",
series.dtype()
),
value.span()?,
Some(value.span()?),
None,
Vec::new(),
)),
};

View File

@ -69,10 +69,12 @@ fn command(
.as_series(call.head)?
.is_duplicated()
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error finding duplicates".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?
.into_series();

View File

@ -78,10 +78,12 @@ fn command(
.as_series(call.head)?
.is_in(&other)
.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error finding in other".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?
.into_series();

View File

@ -66,10 +66,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let mut res = df.as_series(call.head)?.is_unique().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error finding unique values".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
res.rename("is_unique");

View File

@ -65,7 +65,13 @@ fn command(
let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|e| {
ShellError::SpannedLabeledError("Error inverting mask".into(), e.to_string(), call.head)
ShellError::GenericError(
"Error inverting mask".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
let res = bool.not();

View File

@ -82,16 +82,20 @@ fn command(
let bool_mask = match mask.dtype() {
DataType::Boolean => mask.bool().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to bool".into(),
e.to_string(),
mask_span,
Some(mask_span),
None,
Vec::new(),
)
}),
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
"can only use bool series as mask".into(),
mask_span,
Some(mask_span),
None,
Vec::new(),
)),
}?;
@ -101,37 +105,69 @@ fn command(
let res = match value {
Value::Int { val, span } => {
let chunked = series.i64().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to i64".into(), e.to_string(), span)
ShellError::GenericError(
"Error casting to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked.set(bool_mask, Some(val)).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span)
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
Value::Float { val, span } => {
let chunked = series.as_ref().f64().map_err(|e| {
ShellError::SpannedLabeledError("Error casting to f64".into(), e.to_string(), span)
ShellError::GenericError(
"Error casting to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked.set(bool_mask, Some(val)).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span)
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
Value::String { val, span } => {
let chunked = series.as_ref().utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked.set(bool_mask, Some(val.as_ref())).map_err(|e| {
ShellError::SpannedLabeledError("Error setting value".into(), e.to_string(), span)
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
let mut res = res.into_series();
@ -139,13 +175,15 @@ fn command(
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect value type".into(),
format!(
"this value cannot be set in a series of type '{}'",
series.dtype()
),
value.span()?,
Some(value.span()?),
None,
Vec::new(),
)),
};

View File

@ -57,10 +57,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let res = df.as_series(call.head)?.n_unique().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error counting unique values".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -22,11 +22,12 @@ impl RollType {
"max" => Ok(Self::Max),
"sum" => Ok(Self::Sum),
"mean" => Ok(Self::Mean),
_ => Err(ShellError::SpannedLabeledErrorHelp(
_ => Err(ShellError::GenericError(
"Wrong operation".into(),
"Operation not valid for cumulative".into(),
span,
"Allowed values: min, max, sum, mean".into(),
Some(span),
Some("Allowed values: min, max, sum, mean".into()),
Vec::new(),
)),
}
}
@ -123,10 +124,12 @@ fn command(
let series = df.as_series(call.head)?;
if let DataType::Object(_) = series.dtype() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Found object series".into(),
"Series of type object cannot be used for rolling operation".into(),
call.head,
Some(call.head),
None,
Vec::new(),
));
}
@ -146,10 +149,12 @@ fn command(
};
let mut res = res.map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error calculating rolling values".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -75,19 +75,23 @@ fn command(
let other_series = other_df.as_series(other_span)?;
let other_chunked = other_series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"The concatenate only with string columns".into(),
e.to_string(),
other_span,
Some(other_span),
None,
Vec::new(),
)
})?;
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"The concatenate only with string columns".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -71,18 +71,22 @@ fn command(
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"The contains command only with string columns".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
let res = chunked.contains(&pattern).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error searching in series".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -83,18 +83,22 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error convertion to string".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
let mut res = chunked.replace(&pattern, &replace).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error finding pattern other".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -83,18 +83,22 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error convertion to string".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;
let mut res = chunked.replace_all(&pattern, &replace).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error finding pattern other".into(),
e.to_string(),
call.head,
Some(call.head),
None,
Vec::new(),
)
})?;

View File

@ -59,11 +59,12 @@ fn command(
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
call.head,
"The str-lengths command can only be used with string columns".into(),
Some(call.head),
Some("The str-lengths command can only be used with string columns".into()),
Vec::new(),
)
})?;

View File

@ -72,16 +72,23 @@ fn command(
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
})?;
let mut res = chunked.str_slice(start, length).map_err(|e| {
ShellError::SpannedLabeledError("Error slicing series".into(), e.to_string(), call.head)
ShellError::GenericError(
"Error slicing series".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
res.rename(series.name());

View File

@ -69,11 +69,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to date".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
})?;

View File

@ -63,11 +63,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
})?;

View File

@ -63,11 +63,12 @@ fn command(
let series = df.as_series(call.head)?;
let casted = series.utf8().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
})?;

View File

@ -59,11 +59,12 @@ fn command(
let series = df.as_series(call.head)?;
let res = series.unique().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error calculating unique values".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
})?;

View File

@ -64,11 +64,12 @@ fn command(
let series = df.as_series(call.head)?;
let res = series.value_counts().map_err(|e| {
ShellError::SpannedLabeledErrorHelp(
ShellError::GenericError(
"Error calculating value counts values".into(),
e.to_string(),
call.head,
"The str-slice command can only be used with string columns".into(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
})?;

View File

@ -66,10 +66,12 @@ pub(super) fn compute_between_series(
res.rename(&name);
NuDataFrame::series_to_value(res, operation_span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Division error".into(),
e.to_string(),
right.span()?,
Some(right.span()?),
None,
Vec::new(),
)),
}
}
@ -121,10 +123,12 @@ pub(super) fn compute_between_series(
res.rename(&name);
NuDataFrame::series_to_value(res, operation_span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incompatible types".into(),
"unable to cast to boolean".into(),
right.span()?,
Some(right.span()?),
None,
Vec::new(),
)),
}
}
@ -148,10 +152,12 @@ pub(super) fn compute_between_series(
res.rename(&name);
NuDataFrame::series_to_value(res, operation_span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incompatible types".into(),
"unable to cast to boolean".into(),
right.span()?,
Some(right.span()?),
None,
Vec::new(),
)),
}
}
@ -413,10 +419,12 @@ where
let casted = series.i64();
compute_casted_i64(casted, val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -424,13 +432,15 @@ where
let casted = series.i64();
compute_casted_i64(casted, val, f, span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
"Series of type {} can not be used for operations with an i64 value",
series.dtype()
),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -450,10 +460,12 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -476,10 +488,12 @@ where
let casted = series.f64();
compute_casted_f64(casted, val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -487,13 +501,15 @@ where
let casted = series.f64();
compute_casted_f64(casted, val, f, span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
"Series of type {} can not be used for operations with a decimal value",
series.dtype()
),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -513,10 +529,12 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -537,10 +555,12 @@ where
let casted = series.i64();
compare_casted_i64(casted, val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -556,10 +576,12 @@ where
.expect("already checked for casting");
compare_casted_i64(Ok(&casted), val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -567,13 +589,15 @@ where
let casted = series.i64();
compare_casted_i64(casted, val, f, span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
"Series of type {} can not be used for operations with an i64 value",
series.dtype()
),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -593,10 +617,12 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -619,10 +645,12 @@ where
let casted = series.f64();
compare_casted_f64(casted, val, f, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -630,13 +658,15 @@ where
let casted = series.f64();
compare_casted_f64(casted, val, f, span)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
"Series of type {} can not be used for operations with a decimal value",
series.dtype()
),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -656,10 +686,12 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -675,17 +707,21 @@ fn contains_series_pat(series: &Series, pat: &str, span: Span) -> Result<Value,
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Error using contains".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Unable to cast to string".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}

View File

@ -122,7 +122,13 @@ pub fn create_column(
}
DataType::UInt8 => {
let casted = series.u8().map_err(|e| {
ShellError::LabeledError("Error casting column to u8".into(), e.to_string())
ShellError::GenericError(
"Error casting column to u8".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -141,7 +147,13 @@ pub fn create_column(
}
DataType::UInt16 => {
let casted = series.u16().map_err(|e| {
ShellError::LabeledError("Error casting column to u16".into(), e.to_string())
ShellError::GenericError(
"Error casting column to u16".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -160,7 +172,13 @@ pub fn create_column(
}
DataType::UInt32 => {
let casted = series.u32().map_err(|e| {
ShellError::LabeledError("Error casting column to u32".into(), e.to_string())
ShellError::GenericError(
"Error casting column to u32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -179,7 +197,13 @@ pub fn create_column(
}
DataType::UInt64 => {
let casted = series.u64().map_err(|e| {
ShellError::LabeledError("Error casting column to u64".into(), e.to_string())
ShellError::GenericError(
"Error casting column to u64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -198,7 +222,13 @@ pub fn create_column(
}
DataType::Int8 => {
let casted = series.i8().map_err(|e| {
ShellError::LabeledError("Error casting column to i8".into(), e.to_string())
ShellError::GenericError(
"Error casting column to i8".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -217,7 +247,13 @@ pub fn create_column(
}
DataType::Int16 => {
let casted = series.i16().map_err(|e| {
ShellError::LabeledError("Error casting column to i16".into(), e.to_string())
ShellError::GenericError(
"Error casting column to i16".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -236,7 +272,13 @@ pub fn create_column(
}
DataType::Int32 => {
let casted = series.i32().map_err(|e| {
ShellError::LabeledError("Error casting column to i32".into(), e.to_string())
ShellError::GenericError(
"Error casting column to i32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -255,7 +297,13 @@ pub fn create_column(
}
DataType::Int64 => {
let casted = series.i64().map_err(|e| {
ShellError::LabeledError("Error casting column to i64".into(), e.to_string())
ShellError::GenericError(
"Error casting column to i64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -274,7 +322,13 @@ pub fn create_column(
}
DataType::Float32 => {
let casted = series.f32().map_err(|e| {
ShellError::LabeledError("Error casting column to f32".into(), e.to_string())
ShellError::GenericError(
"Error casting column to f32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -293,7 +347,13 @@ pub fn create_column(
}
DataType::Float64 => {
let casted = series.f64().map_err(|e| {
ShellError::LabeledError("Error casting column to f64".into(), e.to_string())
ShellError::GenericError(
"Error casting column to f64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
.into_iter()
@ -309,7 +369,13 @@ pub fn create_column(
}
DataType::Boolean => {
let casted = series.bool().map_err(|e| {
ShellError::LabeledError("Error casting column to bool".into(), e.to_string())
ShellError::GenericError(
"Error casting column to bool".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
@ -326,7 +392,13 @@ pub fn create_column(
}
DataType::Utf8 => {
let casted = series.utf8().map_err(|e| {
ShellError::LabeledError("Error casting column to string".into(), e.to_string())
ShellError::GenericError(
"Error casting column to string".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
@ -350,9 +422,12 @@ pub fn create_column(
.downcast_ref::<ChunkedArray<ObjectType<DataFrameValue>>>();
match casted {
None => Err(ShellError::LabeledError(
None => Err(ShellError::GenericError(
"Error casting object from series".into(),
format!("Object not supported for conversion: {}", x),
"".to_string(),
None,
Some(format!("Object not supported for conversion: {}", x)),
Vec::new(),
)),
Some(ca) => {
let values = ca
@ -371,7 +446,13 @@ pub fn create_column(
}
DataType::Date => {
let casted = series.date().map_err(|e| {
ShellError::LabeledError("Error casting column to date".into(), e.to_string())
ShellError::GenericError(
"Error casting column to date".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
@ -401,7 +482,13 @@ pub fn create_column(
}
DataType::Datetime(_, _) => {
let casted = series.datetime().map_err(|e| {
ShellError::LabeledError("Error casting column to datetime".into(), e.to_string())
ShellError::GenericError(
"Error casting column to datetime".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
@ -431,7 +518,13 @@ pub fn create_column(
}
DataType::Time => {
let casted = series.timestamp(TimeUnit::Nanoseconds).map_err(|e| {
ShellError::LabeledError("Error casting column to time".into(), e.to_string())
ShellError::GenericError(
"Error casting column to time".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let values = casted
@ -449,9 +542,12 @@ pub fn create_column(
Ok(Column::new(casted.name().into(), values))
}
e => Err(ShellError::LabeledError(
e => Err(ShellError::GenericError(
"Error creating Dataframe".into(),
format!("Value not supported in nushell: {}", e),
"".to_string(),
None,
Some(format!("Value not supported in nushell: {}", e)),
Vec::new(),
)),
}
}
@ -620,5 +716,13 @@ pub fn from_parsed_columns(column_values: ColumnMap) -> Result<NuDataFrame, Shel
DataFrame::new(df_series)
.map(NuDataFrame::new)
.map_err(|e| ShellError::LabeledError("Error creating dataframe".into(), e.to_string()))
.map_err(|e| {
ShellError::GenericError(
"Error creating dataframe".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})
}

View File

@ -111,10 +111,12 @@ impl NuDataFrame {
pub fn series_to_value(series: Series, span: Span) -> Result<Value, ShellError> {
match DataFrame::new(vec![series]) {
Ok(dataframe) => Ok(NuDataFrame::dataframe_into_value(dataframe, span)),
Err(e) => Err(ShellError::SpannedLabeledError(
Err(e) => Err(ShellError::GenericError(
"Error creating dataframe".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)),
}
}
@ -152,10 +154,12 @@ impl NuDataFrame {
pub fn try_from_series(columns: Vec<Series>, span: Span) -> Result<Self, ShellError> {
let dataframe = DataFrame::new(columns).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating dataframe".into(),
format!("Unable to create DataFrame: {}", e),
span,
Some(span),
None,
Vec::new(),
)
})?;
@ -183,12 +187,14 @@ impl NuDataFrame {
"dataframe".into(),
"non-dataframe".into(),
span,
None,
)),
},
x => Err(ShellError::CantConvert(
"dataframe".into(),
x.get_type().to_string(),
x.span()?,
None,
)),
}
}
@ -212,7 +218,13 @@ impl NuDataFrame {
})?;
let dataframe = DataFrame::new(vec![s.clone()]).map_err(|e| {
ShellError::SpannedLabeledError("Error creating dataframe".into(), e.to_string(), span)
ShellError::GenericError(
"Error creating dataframe".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
Ok(Self(dataframe))
@ -224,10 +236,12 @@ impl NuDataFrame {
pub fn as_series(&self, span: Span) -> Result<Series, ShellError> {
if !self.is_series() {
return Err(ShellError::SpannedLabeledError(
return Err(ShellError::GenericError(
"Error using as series".into(),
"dataframe has more than one column".into(),
span,
Some(span),
None,
Vec::new(),
));
}

View File

@ -138,10 +138,12 @@ impl NuDataFrame {
.collect::<Vec<Series>>();
let df_new = DataFrame::new(new_cols).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error creating dataframe".into(),
e.to_string(),
span,
Some(span),
None,
Vec::new(),
)
})?;
@ -183,10 +185,12 @@ impl NuDataFrame {
match res {
Ok(s) => Ok(s.clone()),
Err(e) => Err({
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error appending dataframe".into(),
format!("Unable to append: {}", e),
span,
Some(span),
None,
Vec::new(),
)
}),
}
@ -194,10 +198,12 @@ impl NuDataFrame {
.collect::<Result<Vec<Series>, ShellError>>()?;
let df_new = DataFrame::new(new_cols).map_err(|e| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Error appending dataframe".into(),
format!("Unable to append dataframes: {}", e),
span,
Some(span),
None,
Vec::new(),
)
})?;

View File

@ -78,12 +78,14 @@ impl NuGroupBy {
"groupby".into(),
"non-dataframe".into(),
span,
None,
)),
},
x => Err(ShellError::CantConvert(
"groupby".into(),
x.get_type().to_string(),
x.span()?,
None,
)),
}
}
@ -95,7 +97,13 @@ impl NuGroupBy {
pub fn to_groupby(&self) -> Result<GroupBy, ShellError> {
let by = self.dataframe.select_series(&self.by).map_err(|e| {
ShellError::LabeledError("Error creating groupby".into(), e.to_string())
ShellError::GenericError(
"Error creating groupby".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
Ok(GroupBy::new(

View File

@ -13,10 +13,12 @@ pub(crate) fn convert_columns(
let mut col_span = columns
.get(0)
.ok_or_else(|| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Empty column list".into(),
"Empty list found for command".into(),
span,
Some(span),
None,
Vec::new(),
)
})
.and_then(|v| v.span())?;
@ -28,10 +30,12 @@ pub(crate) fn convert_columns(
col_span = span_join(&[col_span, span]);
Ok(Spanned { item: val, span })
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect column format".into(),
"Only string as column name".into(),
span,
Some(span),
None,
Vec::new(),
)),
})
.collect::<Result<Vec<Spanned<String>>, _>>()?;
@ -49,10 +53,12 @@ pub(crate) fn convert_columns_string(
let mut col_span = columns
.get(0)
.ok_or_else(|| {
ShellError::SpannedLabeledError(
ShellError::GenericError(
"Empty column list".into(),
"Empty list found for command".into(),
span,
Some(span),
None,
Vec::new(),
)
})
.and_then(|v| v.span())?;
@ -64,10 +70,12 @@ pub(crate) fn convert_columns_string(
col_span = span_join(&[col_span, span]);
Ok(val)
}
_ => Err(ShellError::SpannedLabeledError(
_ => Err(ShellError::GenericError(
"Incorrect column format".into(),
"Only string as column name".into(),
span,
Some(span),
None,
Vec::new(),
)),
})
.collect::<Result<Vec<String>, _>>()?;