Convert Shellerror::GenericError to named fields (#11230)

# Description

Replace `.to_string()` used in `GenericError` with `.into()` as
`.into()` seems more popular

Replace `Vec::new()` used in `GenericError` with `vec![]` as `vec![]`
seems more popular

(There are so, so many)
This commit is contained in:
Eric Hodel
2023-12-06 15:40:03 -08:00
committed by GitHub
parent b03f1efac4
commit a95a4505ef
160 changed files with 2975 additions and 3228 deletions

View File

@ -69,25 +69,23 @@ fn command(
let new_df = col_string
.first()
.ok_or_else(|| {
ShellError::GenericError(
"Empty names list".into(),
"No column names were found".into(),
Some(col_span),
None,
Vec::new(),
)
.ok_or_else(|| ShellError::GenericError {
error: "Empty names list".into(),
msg: "No column names were found".into(),
span: Some(col_span),
help: None,
inner: vec![],
})
.and_then(|col| {
df.as_ref().drop(&col.item).map_err(|e| {
ShellError::GenericError(
"Error dropping column".into(),
e.to_string(),
Some(col.span),
None,
Vec::new(),
)
})
df.as_ref()
.drop(&col.item)
.map_err(|e| ShellError::GenericError {
error: "Error dropping column".into(),
msg: e.to_string(),
span: Some(col.span),
help: None,
inner: vec![],
})
})?;
// If there are more columns in the drop selection list, these
@ -96,15 +94,15 @@ fn command(
.iter()
.skip(1)
.try_fold(new_df, |new_df, col| {
new_df.drop(&col.item).map_err(|e| {
ShellError::GenericError(
"Error dropping column".into(),
e.to_string(),
Some(col.span),
None,
Vec::new(),
)
})
new_df
.drop(&col.item)
.map_err(|e| ShellError::GenericError {
error: "Error dropping column".into(),
msg: e.to_string(),
span: Some(col.span),
help: None,
inner: vec![],
})
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -100,14 +100,12 @@ fn command(
df.as_ref()
.unique(subset_slice, keep_strategy, None)
.map_err(|e| {
ShellError::GenericError(
"Error dropping duplicates".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error dropping duplicates".into(),
msg: e.to_string(),
span: Some(col_span),
help: None,
inner: vec![],
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -115,14 +115,12 @@ fn command(
df.as_ref()
.drop_nulls(subset_slice)
.map_err(|e| {
ShellError::GenericError(
"Error dropping nulls".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error dropping nulls".into(),
msg: e.to_string(),
span: Some(col_span),
help: None,
inner: vec![],
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -88,14 +88,12 @@ fn command(
df.as_ref()
.to_dummies(None, drop_first)
.map_err(|e| {
ShellError::GenericError(
"Error calculating dummies".into(),
e.to_string(),
Some(call.head),
Some("The only allowed column types for dummies are String or Int".into()),
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error calculating dummies".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The only allowed column types for dummies are String or Int".into()),
inner: vec![],
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -105,26 +105,22 @@ fn command_eager(
))
} else {
let mask = NuDataFrame::try_from_value(mask_value)?.as_series(mask_span)?;
let mask = mask.bool().map_err(|e| {
ShellError::GenericError(
"Error casting to bool".into(),
e.to_string(),
Some(mask_span),
Some("Perhaps you want to use a series with booleans as mask".into()),
Vec::new(),
)
let mask = mask.bool().map_err(|e| ShellError::GenericError {
error: "Error casting to bool".into(),
msg: e.to_string(),
span: Some(mask_span),
help: Some("Perhaps you want to use a series with booleans as mask".into()),
inner: vec![],
})?;
df.as_ref()
.filter(mask)
.map_err(|e| {
ShellError::GenericError(
"Error filtering dataframe".into(),
e.to_string(),
Some(call.head),
Some("The only allowed column types for dummies are String or Int".into()),
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error filtering dataframe".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The only allowed column types for dummies are String or Int".into()),
inner: vec![],
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -70,14 +70,12 @@ fn command(
df.as_ref()
.select(col_string)
.map_err(|e| {
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error selecting columns".into(),
msg: e.to_string(),
span: Some(col_span),
help: None,
inner: vec![],
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -152,38 +152,34 @@ fn command(
let mut res = df
.as_ref()
.melt(&id_col_string, &val_col_string)
.map_err(|e| {
ShellError::GenericError(
"Error calculating melt".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error calculating melt".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
if let Some(name) = &variable_name {
res.rename("variable", &name.item).map_err(|e| {
ShellError::GenericError(
"Error renaming column".into(),
e.to_string(),
Some(name.span),
None,
Vec::new(),
)
})?;
res.rename("variable", &name.item)
.map_err(|e| ShellError::GenericError {
error: "Error renaming column".into(),
msg: e.to_string(),
span: Some(name.span),
help: None,
inner: vec![],
})?;
}
if let Some(name) = &value_name {
res.rename("value", &name.item).map_err(|e| {
ShellError::GenericError(
"Error renaming column".into(),
e.to_string(),
Some(name.span),
None,
Vec::new(),
)
})?;
res.rename("value", &name.item)
.map_err(|e| ShellError::GenericError {
error: "Error renaming column".into(),
msg: e.to_string(),
span: Some(name.span),
help: None,
inner: vec![],
})?;
}
Ok(PipelineData::Value(
@ -198,50 +194,50 @@ fn check_column_datatypes<T: AsRef<str>>(
col_span: Span,
) -> Result<(), ShellError> {
if cols.is_empty() {
return Err(ShellError::GenericError(
"Merge error".into(),
"empty column list".into(),
Some(col_span),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Merge error".into(),
msg: "empty column list".into(),
span: Some(col_span),
help: None,
inner: vec![],
});
}
// Checking if they are same type
if cols.len() > 1 {
for w in cols.windows(2) {
let l_series = df.column(w[0].as_ref()).map_err(|e| {
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
})?;
let l_series = df
.column(w[0].as_ref())
.map_err(|e| ShellError::GenericError {
error: "Error selecting columns".into(),
msg: e.to_string(),
span: Some(col_span),
help: None,
inner: vec![],
})?;
let r_series = df.column(w[1].as_ref()).map_err(|e| {
ShellError::GenericError(
"Error selecting columns".into(),
e.to_string(),
Some(col_span),
None,
Vec::new(),
)
})?;
let r_series = df
.column(w[1].as_ref())
.map_err(|e| ShellError::GenericError {
error: "Error selecting columns".into(),
msg: e.to_string(),
span: Some(col_span),
help: None,
inner: vec![],
})?;
if l_series.dtype() != r_series.dtype() {
return Err(ShellError::GenericError(
"Merge error".into(),
"found different column types in list".into(),
Some(col_span),
Some(format!(
return Err(ShellError::GenericError {
error: "Merge error".into(),
msg: "found different column types in list".into(),
span: Some(col_span),
help: Some(format!(
"datatypes {} and {} are incompatible",
l_series.dtype(),
r_series.dtype()
)),
Vec::new(),
));
inner: vec![],
});
}
}
}

View File

@ -154,14 +154,12 @@ fn from_parquet(
};
let df: NuLazyFrame = LazyFrame::scan_parquet(file, args)
.map_err(|e| {
ShellError::GenericError(
"Parquet reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Parquet reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();
@ -170,14 +168,12 @@ fn from_parquet(
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let columns: Option<Vec<String>> = call.get_flag(engine_state, stack, "columns")?;
let r = File::open(&file.item).map_err(|e| {
ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
let r = File::open(&file.item).map_err(|e| ShellError::GenericError {
error: "Error opening file".into(),
msg: e.to_string(),
span: Some(file.span),
help: None,
inner: vec![],
})?;
let reader = ParquetReader::new(r);
@ -188,14 +184,12 @@ fn from_parquet(
let df: NuDataFrame = reader
.finish()
.map_err(|e| {
ShellError::GenericError(
"Parquet reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Parquet reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();
@ -211,14 +205,12 @@ fn from_avro(
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let columns: Option<Vec<String>> = call.get_flag(engine_state, stack, "columns")?;
let r = File::open(&file.item).map_err(|e| {
ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
let r = File::open(&file.item).map_err(|e| ShellError::GenericError {
error: "Error opening file".into(),
msg: e.to_string(),
span: Some(file.span),
help: None,
inner: vec![],
})?;
let reader = AvroReader::new(r);
@ -229,14 +221,12 @@ fn from_avro(
let df: NuDataFrame = reader
.finish()
.map_err(|e| {
ShellError::GenericError(
"Avro reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Avro reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();
@ -259,14 +249,12 @@ fn from_ipc(
};
let df: NuLazyFrame = LazyFrame::scan_ipc(file, args)
.map_err(|e| {
ShellError::GenericError(
"IPC reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "IPC reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();
@ -275,14 +263,12 @@ fn from_ipc(
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let columns: Option<Vec<String>> = call.get_flag(engine_state, stack, "columns")?;
let r = File::open(&file.item).map_err(|e| {
ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
let r = File::open(&file.item).map_err(|e| ShellError::GenericError {
error: "Error opening file".into(),
msg: e.to_string(),
span: Some(file.span),
help: None,
inner: vec![],
})?;
let reader = IpcReader::new(r);
@ -293,14 +279,12 @@ fn from_ipc(
let df: NuDataFrame = reader
.finish()
.map_err(|e| {
ShellError::GenericError(
"IPC reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "IPC reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();
@ -314,14 +298,12 @@ fn from_json(
call: &Call,
) -> Result<Value, ShellError> {
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let file = File::open(&file.item).map_err(|e| {
ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
let file = File::open(&file.item).map_err(|e| ShellError::GenericError {
error: "Error opening file".into(),
msg: e.to_string(),
span: Some(file.span),
help: None,
inner: vec![],
})?;
let buf_reader = BufReader::new(file);
@ -329,14 +311,12 @@ fn from_json(
let df: NuDataFrame = reader
.finish()
.map_err(|e| {
ShellError::GenericError(
"Json reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Json reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();
@ -350,14 +330,12 @@ fn from_jsonl(
) -> Result<Value, ShellError> {
let infer_schema: Option<usize> = call.get_flag(engine_state, stack, "infer-schema")?;
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let file = File::open(&file.item).map_err(|e| {
ShellError::GenericError(
"Error opening file".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
let file = File::open(&file.item).map_err(|e| ShellError::GenericError {
error: "Error opening file".into(),
msg: e.to_string(),
span: Some(file.span),
help: None,
inner: vec![],
})?;
let buf_reader = BufReader::new(file);
@ -367,14 +345,12 @@ fn from_jsonl(
let df: NuDataFrame = reader
.finish()
.map_err(|e| {
ShellError::GenericError(
"Json lines reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Json lines reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();
@ -400,13 +376,13 @@ fn from_csv(
None => csv_reader,
Some(d) => {
if d.item.len() != 1 {
return Err(ShellError::GenericError(
"Incorrect delimiter".into(),
"Delimiter has to be one character".into(),
Some(d.span),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Incorrect delimiter".into(),
msg: "Delimiter has to be one character".into(),
span: Some(d.span),
help: None,
inner: vec![],
});
} else {
let delimiter = match d.item.chars().next() {
Some(d) => d as u8,
@ -431,14 +407,12 @@ fn from_csv(
let df: NuLazyFrame = csv_reader
.finish()
.map_err(|e| {
ShellError::GenericError(
"Parquet reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Parquet reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();
@ -446,14 +420,12 @@ fn from_csv(
} else {
let file: Spanned<PathBuf> = call.req(engine_state, stack, 0)?;
let csv_reader = CsvReader::from_path(&file.item)
.map_err(|e| {
ShellError::GenericError(
"Error creating CSV reader".into(),
e.to_string(),
Some(file.span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error creating CSV reader".into(),
msg: e.to_string(),
span: Some(file.span),
help: None,
inner: vec![],
})?
.with_encoding(CsvEncoding::LossyUtf8);
@ -461,13 +433,13 @@ fn from_csv(
None => csv_reader,
Some(d) => {
if d.item.len() != 1 {
return Err(ShellError::GenericError(
"Incorrect delimiter".into(),
"Delimiter has to be one character".into(),
Some(d.span),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Incorrect delimiter".into(),
msg: "Delimiter has to be one character".into(),
span: Some(d.span),
help: None,
inner: vec![],
});
} else {
let delimiter = match d.item.chars().next() {
Some(d) => d as u8,
@ -497,14 +469,12 @@ fn from_csv(
let df: NuDataFrame = csv_reader
.finish()
.map_err(|e| {
ShellError::GenericError(
"Parquet reader error".into(),
format!("{e:?}"),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Parquet reader error".into(),
msg: format!("{e:?}"),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();

View File

@ -76,15 +76,15 @@ fn command(
let mut ctx = SQLContext::new();
ctx.register("df", &df.df);
let df_sql = ctx.execute(&sql_query).map_err(|e| {
ShellError::GenericError(
"Dataframe Error".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
let df_sql = ctx
.execute(&sql_query)
.map_err(|e| ShellError::GenericError {
error: "Dataframe Error".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let lazy = NuLazyFrame::new(false, df_sql);
let eager = lazy.collect(call.head)?;

View File

@ -130,15 +130,15 @@ fn command_eager(
let new_names = extract_strings(new_names)?;
for (from, to) in columns.iter().zip(new_names.iter()) {
df.as_mut().rename(from, to).map_err(|e| {
ShellError::GenericError(
"Error renaming".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
df.as_mut()
.rename(from, to)
.map_err(|e| ShellError::GenericError {
error: "Error renaming".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
}
Ok(PipelineData::Value(df.into_value(call.head), None))

View File

@ -97,41 +97,37 @@ fn command(
(Some(rows), None) => df
.as_ref()
.sample_n(&Series::new("s", &[rows.item]), replace, shuffle, seed)
.map_err(|e| {
ShellError::GenericError(
"Error creating sample".into(),
e.to_string(),
Some(rows.span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error creating sample".into(),
msg: e.to_string(),
span: Some(rows.span),
help: None,
inner: vec![],
}),
(None, Some(frac)) => df
.as_ref()
.sample_frac(&Series::new("frac", &[frac.item]), replace, shuffle, seed)
.map_err(|e| {
ShellError::GenericError(
"Error creating sample".into(),
e.to_string(),
Some(frac.span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error creating sample".into(),
msg: e.to_string(),
span: Some(frac.span),
help: None,
inner: vec![],
}),
(Some(_), Some(_)) => Err(ShellError::GenericError(
"Incompatible flags".into(),
"Only one selection criterion allowed".into(),
Some(call.head),
None,
Vec::new(),
)),
(None, None) => Err(ShellError::GenericError(
"No selection".into(),
"No selection criterion was found".into(),
Some(call.head),
Some("Perhaps you want to use the flag -n or -f".into()),
Vec::new(),
)),
(Some(_), Some(_)) => Err(ShellError::GenericError {
error: "Incompatible flags".into(),
msg: "Only one selection criterion allowed".into(),
span: Some(call.head),
help: None,
inner: vec![],
}),
(None, None) => Err(ShellError::GenericError {
error: "No selection".into(),
msg: "No selection criterion was found".into(),
span: Some(call.head),
help: Some("Perhaps you want to use the flag -n or -f".into()),
inner: vec![],
}),
}
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -127,23 +127,23 @@ fn command(
if (&0.0..=&1.0).contains(&val) {
Ok(*val)
} else {
Err(ShellError::GenericError(
"Incorrect value for quantile".to_string(),
"value should be between 0 and 1".to_string(),
Some(span),
None,
Vec::new(),
))
Err(ShellError::GenericError {
error: "Incorrect value for quantile".into(),
msg: "value should be between 0 and 1".into(),
span: Some(span),
help: None,
inner: vec![],
})
}
}
Value::Error { error, .. } => Err(*error.clone()),
_ => Err(ShellError::GenericError(
"Incorrect value for quantile".to_string(),
"value should be a float".to_string(),
Some(span),
None,
Vec::new(),
)),
_ => Err(ShellError::GenericError {
error: "Incorrect value for quantile".into(),
msg: "value should be a float".into(),
span: Some(span),
help: None,
inner: vec![],
}),
}
})
.collect::<Result<Vec<f64>, ShellError>>()
@ -250,14 +250,12 @@ fn command(
let res = head.chain(tail).collect::<Vec<Series>>();
DataFrame::new(res)
.map_err(|e| {
ShellError::GenericError(
"Dataframe Error".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Dataframe Error".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
}

View File

@ -97,47 +97,41 @@ fn command(
let index = NuDataFrame::try_from_value(index_value)?.as_series(index_span)?;
let casted = match index.dtype() {
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => {
index.cast(&DataType::UInt32).map_err(|e| {
ShellError::GenericError(
"Error casting index list".into(),
e.to_string(),
Some(index_span),
None,
Vec::new(),
)
})
}
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
"Series with incorrect type".into(),
Some(call.head),
Some("Consider using a Series with type int type".into()),
Vec::new(),
)),
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => index
.cast(&DataType::UInt32)
.map_err(|e| ShellError::GenericError {
error: "Error casting index list".into(),
msg: e.to_string(),
span: Some(index_span),
help: None,
inner: vec![],
}),
_ => Err(ShellError::GenericError {
error: "Incorrect type".into(),
msg: "Series with incorrect type".into(),
span: Some(call.head),
help: Some("Consider using a Series with type int type".into()),
inner: vec![],
}),
}?;
let indices = casted.u32().map_err(|e| {
ShellError::GenericError(
"Error casting index list".into(),
e.to_string(),
Some(index_span),
None,
Vec::new(),
)
let indices = casted.u32().map_err(|e| ShellError::GenericError {
error: "Error casting index list".into(),
msg: e.to_string(),
span: Some(index_span),
help: None,
inner: vec![],
})?;
NuDataFrame::try_from_pipeline(input, call.head).and_then(|df| {
df.as_ref()
.take(indices)
.map_err(|e| {
ShellError::GenericError(
"Error taking values".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error taking values".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})
.map(|df| PipelineData::Value(NuDataFrame::dataframe_into_value(df, call.head), None))
})

View File

@ -58,25 +58,23 @@ fn command(
let mut df = NuDataFrame::try_from_pipeline(input, call.head)?;
let mut file = File::create(&file_name.item).map_err(|e| {
ShellError::GenericError(
"Error with file name".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
let mut file = File::create(&file_name.item).map_err(|e| ShellError::GenericError {
error: "Error with file name".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
IpcWriter::new(&mut file).finish(df.as_mut()).map_err(|e| {
ShellError::GenericError(
"Error saving file".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
})?;
IpcWriter::new(&mut file)
.finish(df.as_mut())
.map_err(|e| ShellError::GenericError {
error: "Error saving file".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
let file_value = Value::string(format!("saved {:?}", &file_name.item), file_name.span);

View File

@ -85,27 +85,23 @@ fn command(
let mut df = NuDataFrame::try_from_pipeline(input, call.head)?;
let file = File::create(&file_name.item).map_err(|e| {
ShellError::GenericError(
"Error with file name".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
let file = File::create(&file_name.item).map_err(|e| ShellError::GenericError {
error: "Error with file name".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
AvroWriter::new(file)
.with_compression(compression)
.finish(df.as_mut())
.map_err(|e| {
ShellError::GenericError(
"Error saving file".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error saving file".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
let file_value = Value::string(format!("saved {:?}", &file_name.item), file_name.span);

View File

@ -74,14 +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::GenericError(
"Error with file name".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
let mut file = File::create(&file_name.item).map_err(|e| ShellError::GenericError {
error: "Error with file name".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
let writer = CsvWriter::new(&mut file);
@ -96,13 +94,13 @@ fn command(
None => writer,
Some(d) => {
if d.item.len() != 1 {
return Err(ShellError::GenericError(
"Incorrect delimiter".into(),
"Delimiter has to be one char".into(),
Some(d.span),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Incorrect delimiter".into(),
msg: "Delimiter has to be one char".into(),
span: Some(d.span),
help: None,
inner: vec![],
});
} else {
let delimiter = match d.item.chars().next() {
Some(d) => d as u8,
@ -114,15 +112,15 @@ fn command(
}
};
writer.finish(df.as_mut()).map_err(|e| {
ShellError::GenericError(
"Error writing to file".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
})?;
writer
.finish(df.as_mut())
.map_err(|e| ShellError::GenericError {
error: "Error writing to file".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
let file_value = Value::string(format!("saved {:?}", &file_name.item), file_name.span);

View File

@ -58,27 +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::GenericError(
"Error with file name".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
let file = File::create(&file_name.item).map_err(|e| ShellError::GenericError {
error: "Error with file name".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
let buf_writer = BufWriter::new(file);
JsonWriter::new(buf_writer)
.finish(df.as_mut())
.map_err(|e| {
ShellError::GenericError(
"Error saving file".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error saving file".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
let file_value = Value::string(format!("saved {:?}", &file_name.item), file_name.span);

View File

@ -58,25 +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::GenericError(
"Error with file name".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
let file = File::create(&file_name.item).map_err(|e| ShellError::GenericError {
error: "Error with file name".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
ParquetWriter::new(file).finish(df.as_mut()).map_err(|e| {
ShellError::GenericError(
"Error saving file".into(),
e.to_string(),
Some(file_name.span),
None,
Vec::new(),
)
})?;
ParquetWriter::new(file)
.finish(df.as_mut())
.map_err(|e| ShellError::GenericError {
error: "Error saving file".into(),
msg: e.to_string(),
span: Some(file_name.span),
help: None,
inner: vec![],
})?;
let file_value = Value::string(format!("saved {:?}", &file_name.item), file_name.span);

View File

@ -151,14 +151,12 @@ fn command_eager(
df.as_mut()
.with_column(series)
.map_err(|e| {
ShellError::GenericError(
"Error adding column to dataframe".into(),
e.to_string(),
Some(column_span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error adding column to dataframe".into(),
msg: e.to_string(),
span: Some(column_span),
help: None,
inner: vec![],
})
.map(|df| {
PipelineData::Value(

View File

@ -125,13 +125,13 @@ impl Command for LazyAggregate {
let dtype = schema.get(name.as_str());
if matches!(dtype, Some(DataType::Object(..))) {
return Err(ShellError::GenericError(
"Object type column not supported for aggregation".into(),
format!("Column '{name}' is type Object"),
Some(call.head),
Some("Aggregations cannot be performed on Object type columns. Use dtype command to check column types".into()),
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Object type column not supported for aggregation".into(),
msg: format!("Column '{name}' is type Object"),
span: Some(call.head),
help: Some("Aggregations cannot be performed on Object type columns. Use dtype command to check column types".into()),
inner: vec![],
});
}
}
}

View File

@ -67,14 +67,12 @@ impl Command for LazyFetch {
let eager: NuDataFrame = lazy
.into_polars()
.fetch(rows as usize)
.map_err(|e| {
ShellError::GenericError(
"Error fetching rows".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error fetching rows".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into();

View File

@ -118,13 +118,13 @@ impl Command for LazySortBy {
.get_flag::<Value>(engine_state, stack, "reverse")?
.expect("already checked and it exists")
.span();
return Err(ShellError::GenericError(
"Incorrect list size".into(),
"Size doesn't match expression list".into(),
Some(span),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Incorrect list size".into(),
msg: "Size doesn't match expression list".into(),
span: Some(span),
help: None,
inner: vec![],
});
} else {
list
}

View File

@ -78,14 +78,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| {
ShellError::GenericError(
"Error converting to bool".into(),
"all-false only works with series of type bool".into(),
Some(call.head),
None,
Vec::new(),
)
let bool = series.bool().map_err(|_| ShellError::GenericError {
error: "Error converting to bool".into(),
msg: "all-false only works with series of type bool".into(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let value = Value::bool(!bool.any(), call.head);

View File

@ -78,14 +78,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|_| {
ShellError::GenericError(
"Error converting to bool".into(),
"all-false only works with series of type bool".into(),
Some(call.head),
None,
Vec::new(),
)
let bool = series.bool().map_err(|_| ShellError::GenericError {
error: "Error converting to bool".into(),
msg: "all-false only works with series of type bool".into(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let value = Value::bool(bool.all(), call.head);

View File

@ -22,13 +22,13 @@ impl CumType {
"min" => Ok(Self::Min),
"max" => Ok(Self::Max),
"sum" => Ok(Self::Sum),
_ => Err(ShellError::GenericError(
"Wrong operation".into(),
"Operation not valid for cumulative".into(),
Some(span),
Some("Allowed values: max, min, sum".into()),
Vec::new(),
)),
_ => Err(ShellError::GenericError {
error: "Wrong operation".into(),
msg: "Operation not valid for cumulative".into(),
span: Some(span),
help: Some("Allowed values: max, min, sum".into()),
inner: vec![],
}),
}
}
@ -109,13 +109,13 @@ fn command(
let series = df.as_series(call.head)?;
if let DataType::Object(_) = series.dtype() {
return Err(ShellError::GenericError(
"Found object series".into(),
"Series of type object cannot be used for cumulative operation".into(),
Some(call.head),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Found object series".into(),
msg: "Series of type object cannot be used for cumulative operation".into(),
span: Some(call.head),
help: None,
inner: vec![],
});
}
let cum_type = CumType::from_str(&cum_type.item, cum_type.span)?;
@ -124,14 +124,12 @@ fn command(
CumType::Min => cum_min(&series, reverse),
CumType::Sum => cum_sum(&series, reverse),
}
.map_err(|e| {
ShellError::GenericError(
"Error creating cumulative".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error creating cumulative".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let name = format!("{}_{}", series.name(), cum_type.to_str());

View File

@ -68,14 +68,12 @@ 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::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting to string".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = if not_exact {
@ -85,14 +83,12 @@ fn command(
};
let mut res = res
.map_err(|e| {
ShellError::GenericError(
"Error creating datetime".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error creating datetime".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into_series();

View File

@ -132,14 +132,12 @@ 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::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting to string".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = if not_exact {
@ -162,14 +160,12 @@ fn command(
};
let mut res = res
.map_err(|e| {
ShellError::GenericError(
"Error creating datetime".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error creating datetime".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.day().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.hour().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.minute().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.month().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.nanosecond().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.ordinal().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.second().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.week().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.weekday().into_series();

View File

@ -65,14 +65,12 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to datetime type".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to datetime type".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = casted.year().into_series();

View File

@ -67,13 +67,13 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let columns = df.as_ref().get_column_names();
if columns.len() > 1 {
return Err(ShellError::GenericError(
"Error using as series".into(),
"dataframe has more than one column".into(),
Some(call.head),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Error using as series".into(),
msg: "dataframe has more than one column".into(),
span: Some(call.head),
help: None,
inner: vec![],
});
}
match columns.first() {
@ -85,14 +85,12 @@ fn command(
.lazy()
.select(&[expression])
.collect()
.map_err(|err| {
ShellError::GenericError(
"Error creating index column".into(),
err.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|err| ShellError::GenericError {
error: "Error creating index column".into(),
msg: err.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let value = NuDataFrame::dataframe_into_value(res, call.head);

View File

@ -69,14 +69,12 @@ fn command(
let mut res = df
.as_series(call.head)?
.arg_unique()
.map_err(|e| {
ShellError::GenericError(
"Error extracting unique values".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error extracting unique values".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into_series();
res.rename("arg_unique");

View File

@ -86,36 +86,33 @@ fn command(
let indices = NuDataFrame::try_from_value(indices_value)?.as_series(indices_span)?;
let casted = match indices.dtype() {
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => {
indices.as_ref().cast(&DataType::UInt32).map_err(|e| {
ShellError::GenericError(
"Error casting indices".into(),
e.to_string(),
Some(indices_span),
None,
Vec::new(),
)
})
}
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
"Series with incorrect type".into(),
Some(indices_span),
Some("Consider using a Series with type int type".into()),
Vec::new(),
)),
DataType::UInt32 | DataType::UInt64 | DataType::Int32 | DataType::Int64 => indices
.as_ref()
.cast(&DataType::UInt32)
.map_err(|e| ShellError::GenericError {
error: "Error casting indices".into(),
msg: e.to_string(),
span: Some(indices_span),
help: None,
inner: vec![],
}),
_ => Err(ShellError::GenericError {
error: "Incorrect type".into(),
msg: "Series with incorrect type".into(),
span: Some(indices_span),
help: Some("Consider using a Series with type int type".into()),
inner: vec![],
}),
}?;
let indices = casted
.u32()
.map_err(|e| {
ShellError::GenericError(
"Error casting indices".into(),
e.to_string(),
Some(indices_span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error casting indices".into(),
msg: e.to_string(),
span: Some(indices_span),
help: None,
inner: vec![],
})?
.into_iter()
.flatten();
@ -124,92 +121,85 @@ fn command(
let series = df.as_series(call.head)?;
let span = value.span();
let res = match value {
Value::Int { val, .. } => {
let chunked = series.i64().map_err(|e| {
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::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, .. } => {
let chunked = series.f64().map_err(|e| {
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::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, .. } => {
let chunked = series.utf8().map_err(|e| {
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked
.set_at_idx(indices, Some(val.as_ref()))
.map_err(|e| {
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
let res =
match value {
Value::Int { val, .. } => {
let chunked = series.i64().map_err(|e| ShellError::GenericError {
error: "Error casting to i64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
let mut res = res.into_series();
res.rename("string");
let res = chunked.set_at_idx(indices, Some(val)).map_err(|e| {
ShellError::GenericError {
error: "Error setting value".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
_ => Err(ShellError::GenericError(
"Incorrect value type".into(),
format!(
"this value cannot be set in a series of type '{}'",
series.dtype()
),
Some(span),
None,
Vec::new(),
)),
};
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
Value::Float { val, .. } => {
let chunked = series.f64().map_err(|e| ShellError::GenericError {
error: "Error casting to f64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
let res = chunked.set_at_idx(indices, Some(val)).map_err(|e| {
ShellError::GenericError {
error: "Error setting value".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
Value::String { val, .. } => {
let chunked = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting to string".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
let res = chunked
.set_at_idx(indices, Some(val.as_ref()))
.map_err(|e| ShellError::GenericError {
error: "Error setting value".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
let mut res = res.into_series();
res.rename("string");
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
_ => Err(ShellError::GenericError {
error: "Incorrect value type".into(),
msg: format!(
"this value cannot be set in a series of type '{}'",
series.dtype()
),
span: Some(span),
help: None,
inner: vec![],
}),
};
res.map(|df| PipelineData::Value(NuDataFrame::into_value(df, call.head), None))
}

View File

@ -94,14 +94,12 @@ fn command(
let mut res = df
.as_ref()
.is_duplicated()
.map_err(|e| {
ShellError::GenericError(
"Error finding duplicates".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error finding duplicates".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into_series();

View File

@ -79,14 +79,12 @@ fn command(
let other = other_df.as_series(other_span)?;
let mut res = is_in(&df, &other)
.map_err(|e| {
ShellError::GenericError(
"Error finding in other".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error finding in other".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into_series();

View File

@ -93,14 +93,12 @@ fn command(
let mut res = df
.as_ref()
.is_unique()
.map_err(|e| {
ShellError::GenericError(
"Error finding unique values".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error finding unique values".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into_series();

View File

@ -68,14 +68,12 @@ fn command(
) -> Result<PipelineData, ShellError> {
let series = df.as_series(call.head)?;
let bool = series.bool().map_err(|e| {
ShellError::GenericError(
"Error inverting mask".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let bool = series.bool().map_err(|e| ShellError::GenericError {
error: "Error inverting mask".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = bool.not();

View File

@ -85,22 +85,20 @@ fn command(
let mask = NuDataFrame::try_from_value(mask_value)?.as_series(mask_span)?;
let bool_mask = match mask.dtype() {
DataType::Boolean => mask.bool().map_err(|e| {
ShellError::GenericError(
"Error casting to bool".into(),
e.to_string(),
Some(mask_span),
None,
Vec::new(),
)
DataType::Boolean => mask.bool().map_err(|e| ShellError::GenericError {
error: "Error casting to bool".into(),
msg: e.to_string(),
span: Some(mask_span),
help: None,
inner: vec![],
}),
_ => Err(ShellError::GenericError {
error: "Incorrect type".into(),
msg: "can only use bool series as mask".into(),
span: Some(mask_span),
help: None,
inner: vec![],
}),
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
"can only use bool series as mask".into(),
Some(mask_span),
None,
Vec::new(),
)),
}?;
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
@ -108,70 +106,64 @@ fn command(
let span = value.span();
let res = match value {
Value::Int { val, .. } => {
let chunked = series.i64().map_err(|e| {
ShellError::GenericError(
"Error casting to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
let chunked = series.i64().map_err(|e| ShellError::GenericError {
error: "Error casting to i64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
let res = chunked.set(bool_mask, Some(val)).map_err(|e| {
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked
.set(bool_mask, Some(val))
.map_err(|e| ShellError::GenericError {
error: "Error setting value".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
Value::Float { val, .. } => {
let chunked = series.f64().map_err(|e| {
ShellError::GenericError(
"Error casting to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
let chunked = series.f64().map_err(|e| ShellError::GenericError {
error: "Error casting to f64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
let res = chunked.set(bool_mask, Some(val)).map_err(|e| {
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
})?;
let res = chunked
.set(bool_mask, Some(val))
.map_err(|e| ShellError::GenericError {
error: "Error setting value".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
Value::String { val, .. } => {
let chunked = series.utf8().map_err(|e| {
ShellError::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
let chunked = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting to string".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
let res = chunked.set(bool_mask, Some(val.as_ref())).map_err(|e| {
ShellError::GenericError(
"Error setting value".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
ShellError::GenericError {
error: "Error setting value".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}
})?;
let mut res = res.into_series();
@ -179,16 +171,16 @@ fn command(
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
}
_ => Err(ShellError::GenericError(
"Incorrect value type".into(),
format!(
_ => Err(ShellError::GenericError {
error: "Incorrect value type".into(),
msg: format!(
"this value cannot be set in a series of type '{}'",
series.dtype()
),
Some(span),
None,
Vec::new(),
)),
span: Some(span),
help: None,
inner: vec![],
}),
};
res.map(|df| PipelineData::Value(NuDataFrame::into_value(df, call.head), None))

View File

@ -83,15 +83,16 @@ fn command(
call: &Call,
df: NuDataFrame,
) -> Result<PipelineData, ShellError> {
let res = df.as_series(call.head)?.n_unique().map_err(|e| {
ShellError::GenericError(
"Error counting unique values".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
let res = df
.as_series(call.head)?
.n_unique()
.map_err(|e| ShellError::GenericError {
error: "Error counting unique values".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let value = Value::int(res as i64, call.head);

View File

@ -23,13 +23,13 @@ impl RollType {
"max" => Ok(Self::Max),
"sum" => Ok(Self::Sum),
"mean" => Ok(Self::Mean),
_ => Err(ShellError::GenericError(
"Wrong operation".into(),
"Operation not valid for cumulative".into(),
Some(span),
Some("Allowed values: min, max, sum, mean".into()),
Vec::new(),
)),
_ => Err(ShellError::GenericError {
error: "Wrong operation".into(),
msg: "Operation not valid for cumulative".into(),
span: Some(span),
help: Some("Allowed values: min, max, sum, mean".into()),
inner: vec![],
}),
}
}
@ -129,13 +129,13 @@ fn command(
let series = df.as_series(call.head)?;
if let DataType::Object(_) = series.dtype() {
return Err(ShellError::GenericError(
"Found object series".into(),
"Series of type object cannot be used for rolling operation".into(),
Some(call.head),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Found object series".into(),
msg: "Series of type object cannot be used for rolling operation".into(),
span: Some(call.head),
help: None,
inner: vec![],
});
}
let roll_type = RollType::from_str(&roll_type.item, roll_type.span)?;
@ -158,14 +158,12 @@ fn command(
RollType::Mean => series.rolling_mean(rolling_opts),
};
let mut res = res.map_err(|e| {
ShellError::GenericError(
"Error calculating rolling values".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let mut res = res.map_err(|e| ShellError::GenericError {
error: "Error calculating rolling values".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let name = format!("{}_{}", series.name(), roll_type.to_str());

View File

@ -78,25 +78,21 @@ fn command(
let other_df = NuDataFrame::try_from_value(other)?;
let other_series = other_df.as_series(other_span)?;
let other_chunked = other_series.utf8().map_err(|e| {
ShellError::GenericError(
"The concatenate only with string columns".into(),
e.to_string(),
Some(other_span),
None,
Vec::new(),
)
let other_chunked = other_series.utf8().map_err(|e| ShellError::GenericError {
error: "The concatenate only with string columns".into(),
msg: e.to_string(),
span: Some(other_span),
help: None,
inner: vec![],
})?;
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::GenericError(
"The concatenate only with string columns".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let chunked = series.utf8().map_err(|e| ShellError::GenericError {
error: "The concatenate only with string columns".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let mut res = chunked.concat(other_chunked);

View File

@ -74,25 +74,23 @@ fn command(
let pattern: String = call.req(engine_state, stack, 0)?;
let series = df.as_series(call.head)?;
let chunked = series.utf8().map_err(|e| {
ShellError::GenericError(
"The contains command only with string columns".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let chunked = series.utf8().map_err(|e| ShellError::GenericError {
error: "The contains command only with string columns".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let res = chunked.contains(&pattern, false).map_err(|e| {
ShellError::GenericError(
"Error searching in series".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
let res = chunked
.contains(&pattern, false)
.map_err(|e| ShellError::GenericError {
error: "Error searching in series".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)
.map(|df| PipelineData::Value(NuDataFrame::into_value(df, call.head), None))

View File

@ -86,25 +86,23 @@ 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::GenericError(
"Error conversion to string".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let chunked = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error conversion to string".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let mut res = chunked.replace(&pattern, &replace).map_err(|e| {
ShellError::GenericError(
"Error finding pattern other".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
let mut res = chunked
.replace(&pattern, &replace)
.map_err(|e| ShellError::GenericError {
error: "Error finding pattern other".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
res.rename(series.name());

View File

@ -86,25 +86,24 @@ 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::GenericError(
"Error conversion to string".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
let chunked = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error conversion to string".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
let mut res = chunked.replace_all(&pattern, &replace).map_err(|e| {
ShellError::GenericError(
"Error finding pattern other".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
})?;
let mut res =
chunked
.replace_all(&pattern, &replace)
.map_err(|e| ShellError::GenericError {
error: "Error finding pattern other".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?;
res.rename(series.name());

View File

@ -63,14 +63,12 @@ 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::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
Some("The str-lengths command can only be used with string columns".into()),
Vec::new(),
)
let chunked = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting to string".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The str-lengths command can only be used with string columns".into()),
inner: vec![],
})?;
let res = chunked.as_ref().str_len_bytes().into_series();

View File

@ -75,14 +75,12 @@ 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::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
let chunked = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting to string".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The str-slice command can only be used with string columns".into()),
inner: vec![],
})?;
let mut res = chunked.str_slice(start, length);

View File

@ -72,26 +72,22 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting to date".into(),
e.to_string(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting to date".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The str-slice command can only be used with string columns".into()),
inner: vec![],
})?;
let res = casted
.strftime(&fmt)
.map_err(|e| {
ShellError::GenericError(
"Error formatting datetime".into(),
e.to_string(),
Some(call.head),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error formatting datetime".into(),
msg: e.to_string(),
span: Some(call.head),
help: None,
inner: vec![],
})?
.into_series();

View File

@ -67,14 +67,12 @@ 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::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
let casted = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting to string".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The str-slice command can only be used with string columns".into()),
inner: vec![],
})?;
let mut res = casted.to_lowercase();

View File

@ -71,14 +71,12 @@ 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::GenericError(
"Error casting to string".into(),
e.to_string(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
let casted = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting to string".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The str-slice command can only be used with string columns".into()),
inner: vec![],
})?;
let mut res = casted.to_uppercase();

View File

@ -96,14 +96,12 @@ fn command_eager(
) -> Result<PipelineData, ShellError> {
let series = df.as_series(call.head)?;
let res = series.unique().map_err(|e| {
ShellError::GenericError(
"Error calculating unique values".into(),
e.to_string(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
let res = series.unique().map_err(|e| ShellError::GenericError {
error: "Error calculating unique values".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The str-slice command can only be used with string columns".into()),
inner: vec![],
})?;
NuDataFrame::try_from_series(vec![res.into_series()], call.head)

View File

@ -70,15 +70,15 @@ fn command(
let df = NuDataFrame::try_from_pipeline(input, call.head)?;
let series = df.as_series(call.head)?;
let res = series.value_counts(false, false).map_err(|e| {
ShellError::GenericError(
"Error calculating value counts values".into(),
e.to_string(),
Some(call.head),
Some("The str-slice command can only be used with string columns".into()),
Vec::new(),
)
})?;
let res = series
.value_counts(false, false)
.map_err(|e| ShellError::GenericError {
error: "Error calculating value counts values".into(),
msg: e.to_string(),
span: Some(call.head),
help: Some("The str-slice command can only be used with string columns".into()),
inner: vec![],
})?;
Ok(PipelineData::Value(
NuDataFrame::dataframe_into_value(res, call.head),

View File

@ -68,13 +68,13 @@ pub(super) fn compute_between_series(
res.rename(&name);
NuDataFrame::series_to_value(res, operation_span)
}
Err(e) => Err(ShellError::GenericError(
"Division error".into(),
e.to_string(),
Some(right.span()),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Division error".into(),
msg: e.to_string(),
span: Some(right.span()),
help: None,
inner: vec![],
}),
}
}
Operator::Comparison(Comparison::Equal) => {
@ -119,13 +119,13 @@ pub(super) fn compute_between_series(
res.rename(&name);
NuDataFrame::series_to_value(res, operation_span)
}
_ => Err(ShellError::GenericError(
"Incompatible types".into(),
"unable to cast to boolean".into(),
Some(right.span()),
None,
Vec::new(),
)),
_ => Err(ShellError::GenericError {
error: "Incompatible types".into(),
msg: "unable to cast to boolean".into(),
span: Some(right.span()),
help: None,
inner: vec![],
}),
}
}
_ => Err(ShellError::IncompatibleParametersSingle {
@ -148,13 +148,13 @@ pub(super) fn compute_between_series(
res.rename(&name);
NuDataFrame::series_to_value(res, operation_span)
}
_ => Err(ShellError::GenericError(
"Incompatible types".into(),
"unable to cast to boolean".into(),
Some(right.span()),
None,
Vec::new(),
)),
_ => Err(ShellError::GenericError {
error: "Incompatible types".into(),
msg: "unable to cast to boolean".into(),
span: Some(right.span()),
help: None,
inner: vec![],
}),
}
}
_ => Err(ShellError::IncompatibleParametersSingle {
@ -186,14 +186,12 @@ where
F: Fn(&'s Series, &'s Series) -> Result<ChunkedArray<BooleanType>, PolarsError>,
{
let mut res = f(lhs, rhs)
.map_err(|e| {
ShellError::GenericError(
"Equality error".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Equality error".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?
.into_series();
@ -458,29 +456,29 @@ where
let casted = series.i64();
compute_casted_i64(casted, val, f, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to i64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
DataType::Int64 => {
let casted = series.i64();
compute_casted_i64(casted, val, f, span)
}
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
_ => Err(ShellError::GenericError {
error: "Incorrect type".into(),
msg: format!(
"Series of type {} can not be used for operations with an i64 value",
series.dtype()
),
Some(span),
None,
Vec::new(),
)),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -499,13 +497,13 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to i64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -522,29 +520,29 @@ where
let casted = series.f64();
compute_casted_f64(casted, val, f, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to f64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
DataType::Float64 => {
let casted = series.f64();
compute_casted_f64(casted, val, f, span)
}
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
_ => Err(ShellError::GenericError {
error: "Incorrect type".into(),
msg: format!(
"Series of type {} can not be used for operations with a float value",
series.dtype()
),
Some(span),
None,
Vec::new(),
)),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -563,13 +561,13 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to f64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -586,13 +584,13 @@ where
let casted = series.i64();
compare_casted_i64(casted, val, f, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to f64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
DataType::Date => {
@ -607,29 +605,29 @@ where
.expect("already checked for casting");
compare_casted_i64(Ok(&casted), val, f, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to f64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
DataType::Int64 => {
let casted = series.i64();
compare_casted_i64(casted, val, f, span)
}
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
_ => Err(ShellError::GenericError {
error: "Incorrect type".into(),
msg: format!(
"Series of type {} can not be used for operations with an i64 value",
series.dtype()
),
Some(span),
None,
Vec::new(),
)),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -648,13 +646,13 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to i64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -671,29 +669,29 @@ where
let casted = series.f64();
compare_casted_f64(casted, val, f, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to i64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to i64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
DataType::Float64 => {
let casted = series.f64();
compare_casted_f64(casted, val, f, span)
}
_ => Err(ShellError::GenericError(
"Incorrect type".into(),
format!(
_ => Err(ShellError::GenericError {
error: "Incorrect type".into(),
msg: format!(
"Series of type {} can not be used for operations with a float value",
series.dtype()
),
Some(span),
None,
Vec::new(),
)),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -712,13 +710,13 @@ where
let res = res.into_series();
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to f64".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to f64".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -733,22 +731,22 @@ 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::GenericError(
"Error using contains".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Error using contains".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to string".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to string".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -761,12 +759,12 @@ fn add_string_to_series(series: &Series, pat: &str, span: Span) -> Result<Value,
NuDataFrame::series_to_value(res, span)
}
Err(e) => Err(ShellError::GenericError(
"Unable to cast to string".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Unable to cast to string".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}

View File

@ -287,14 +287,12 @@ pub fn from_parsed_columns(column_values: ColumnMap) -> Result<NuDataFrame, Shel
DataFrame::new(df_series)
.map(|df| NuDataFrame::new(false, df))
.map_err(|e| {
ShellError::GenericError(
"Error creating dataframe".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error creating dataframe".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})
}
@ -314,16 +312,14 @@ fn input_type_list_to_series(
list_type: &InputType,
values: &[Value],
) -> Result<Series, ShellError> {
let inconsistent_error = |_| {
ShellError::GenericError(
format!(
"column {name} contains a list with inconsistent types: Expecting: {list_type:?}"
),
"".to_string(),
None,
None,
Vec::new(),
)
let inconsistent_error = |_| ShellError::GenericError {
error: format!(
"column {name} contains a list with inconsistent types: Expecting: {list_type:?}"
),
msg: "".into(),
span: None,
help: None,
inner: vec![],
};
match *list_type {
// list of boolean values
@ -423,14 +419,12 @@ fn input_type_list_to_series(
builder
.append_series(&dt_chunked.into_series())
.map_err(|e| {
ShellError::GenericError(
"Error appending to series".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error appending to series".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?
}
let res = builder.finish();
@ -463,14 +457,12 @@ fn series_to_values(
Ok(values)
}
DataType::UInt8 => {
let casted = series.u8().map_err(|e| {
ShellError::GenericError(
"Error casting column to u8".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.u8().map_err(|e| ShellError::GenericError {
error: "Error casting column to u8".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -488,14 +480,12 @@ fn series_to_values(
Ok(values)
}
DataType::UInt16 => {
let casted = series.u16().map_err(|e| {
ShellError::GenericError(
"Error casting column to u16".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.u16().map_err(|e| ShellError::GenericError {
error: "Error casting column to u16".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -513,14 +503,12 @@ fn series_to_values(
Ok(values)
}
DataType::UInt32 => {
let casted = series.u32().map_err(|e| {
ShellError::GenericError(
"Error casting column to u32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.u32().map_err(|e| ShellError::GenericError {
error: "Error casting column to u32".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -538,14 +526,12 @@ fn series_to_values(
Ok(values)
}
DataType::UInt64 => {
let casted = series.u64().map_err(|e| {
ShellError::GenericError(
"Error casting column to u64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.u64().map_err(|e| ShellError::GenericError {
error: "Error casting column to u64".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -563,14 +549,12 @@ fn series_to_values(
Ok(values)
}
DataType::Int8 => {
let casted = series.i8().map_err(|e| {
ShellError::GenericError(
"Error casting column to i8".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.i8().map_err(|e| ShellError::GenericError {
error: "Error casting column to i8".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -588,14 +572,12 @@ fn series_to_values(
Ok(values)
}
DataType::Int16 => {
let casted = series.i16().map_err(|e| {
ShellError::GenericError(
"Error casting column to i16".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.i16().map_err(|e| ShellError::GenericError {
error: "Error casting column to i16".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -613,14 +595,12 @@ fn series_to_values(
Ok(values)
}
DataType::Int32 => {
let casted = series.i32().map_err(|e| {
ShellError::GenericError(
"Error casting column to i32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.i32().map_err(|e| ShellError::GenericError {
error: "Error casting column to i32".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -638,14 +618,12 @@ fn series_to_values(
Ok(values)
}
DataType::Int64 => {
let casted = series.i64().map_err(|e| {
ShellError::GenericError(
"Error casting column to i64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.i64().map_err(|e| ShellError::GenericError {
error: "Error casting column to i64".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -663,14 +641,12 @@ fn series_to_values(
Ok(values)
}
DataType::Float32 => {
let casted = series.f32().map_err(|e| {
ShellError::GenericError(
"Error casting column to f32".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.f32().map_err(|e| ShellError::GenericError {
error: "Error casting column to f32".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -688,14 +664,12 @@ fn series_to_values(
Ok(values)
}
DataType::Float64 => {
let casted = series.f64().map_err(|e| {
ShellError::GenericError(
"Error casting column to f64".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.f64().map_err(|e| ShellError::GenericError {
error: "Error casting column to f64".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -713,14 +687,12 @@ fn series_to_values(
Ok(values)
}
DataType::Boolean => {
let casted = series.bool().map_err(|e| {
ShellError::GenericError(
"Error casting column to bool".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.bool().map_err(|e| ShellError::GenericError {
error: "Error casting column to bool".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -738,14 +710,12 @@ fn series_to_values(
Ok(values)
}
DataType::Utf8 => {
let casted = series.utf8().map_err(|e| {
ShellError::GenericError(
"Error casting column to string".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.utf8().map_err(|e| ShellError::GenericError {
error: "Error casting column to string".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -768,13 +738,13 @@ fn series_to_values(
.downcast_ref::<ChunkedArray<ObjectType<DataFrameValue>>>();
match casted {
None => Err(ShellError::GenericError(
"Error casting object from series".into(),
"".to_string(),
None,
Some(format!("Object not supported for conversion: {x}")),
Vec::new(),
)),
None => Err(ShellError::GenericError {
error: "Error casting object from series".into(),
msg: "".into(),
span: None,
help: Some(format!("Object not supported for conversion: {x}")),
inner: vec![],
}),
Some(ca) => {
let it = ca.into_iter();
let values = if let (Some(size), Some(from_row)) = (maybe_size, maybe_from_row)
@ -796,13 +766,13 @@ fn series_to_values(
DataType::List(x) => {
let casted = series.as_any().downcast_ref::<ChunkedArray<ListType>>();
match casted {
None => Err(ShellError::GenericError(
"Error casting list from series".into(),
"".to_string(),
None,
Some(format!("List not supported for conversion: {x}")),
Vec::new(),
)),
None => Err(ShellError::GenericError {
error: "Error casting list from series".into(),
msg: "".into(),
span: None,
help: Some(format!("List not supported for conversion: {x}")),
inner: vec![],
}),
Some(ca) => {
let it = ca.into_iter();
let values: Vec<Value> =
@ -831,14 +801,12 @@ fn series_to_values(
}
}
DataType::Date => {
let casted = series.date().map_err(|e| {
ShellError::GenericError(
"Error casting column to date".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.date().map_err(|e| ShellError::GenericError {
error: "Error casting column to date".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -894,14 +862,12 @@ fn series_to_values(
Ok(values)
}
DataType::Datetime(time_unit, _) => {
let casted = series.datetime().map_err(|e| {
ShellError::GenericError(
"Error casting column to datetime".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
let casted = series.datetime().map_err(|e| ShellError::GenericError {
error: "Error casting column to datetime".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
@ -962,15 +928,16 @@ fn series_to_values(
Ok(values)
}
DataType::Time => {
let casted = series.timestamp(TimeUnit::Nanoseconds).map_err(|e| {
ShellError::GenericError(
"Error casting column to time".into(),
"".to_string(),
None,
Some(e.to_string()),
Vec::new(),
)
})?;
let casted =
series
.timestamp(TimeUnit::Nanoseconds)
.map_err(|e| ShellError::GenericError {
error: "Error casting column to time".into(),
msg: "".into(),
span: None,
help: Some(e.to_string()),
inner: vec![],
})?;
let it = casted.into_iter();
let values = if let (Some(size), Some(from_row)) = (maybe_size, maybe_from_row) {
@ -986,13 +953,13 @@ fn series_to_values(
Ok(values)
}
e => Err(ShellError::GenericError(
"Error creating Dataframe".into(),
"".to_string(),
None,
Some(format!("Value not supported in nushell: {e}")),
Vec::new(),
)),
e => Err(ShellError::GenericError {
error: "Error creating Dataframe".into(),
msg: "".to_string(),
span: None,
help: Some(format!("Value not supported in nushell: {e}")),
inner: vec![],
}),
}
}

View File

@ -131,13 +131,13 @@ 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::GenericError(
"Error creating dataframe".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)),
Err(e) => Err(ShellError::GenericError {
error: "Error creating dataframe".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
}),
}
}
@ -174,14 +174,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::GenericError(
"Error creating dataframe".into(),
format!("Unable to create DataFrame: {e}"),
Some(span),
None,
Vec::new(),
)
let dataframe = DataFrame::new(columns).map_err(|e| ShellError::GenericError {
error: "Error creating dataframe".into(),
msg: format!("Unable to create DataFrame: {e}"),
span: Some(span),
help: None,
inner: vec![],
})?;
Ok(Self::new(false, dataframe))
@ -301,14 +299,12 @@ impl NuDataFrame {
}
})?;
let df = DataFrame::new(vec![s.clone()]).map_err(|e| {
ShellError::GenericError(
"Error creating dataframe".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
let df = DataFrame::new(vec![s.clone()]).map_err(|e| ShellError::GenericError {
error: "Error creating dataframe".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
Ok(Self {
@ -323,13 +319,13 @@ impl NuDataFrame {
pub fn as_series(&self, span: Span) -> Result<Series, ShellError> {
if !self.is_series() {
return Err(ShellError::GenericError(
"Error using as series".into(),
"dataframe has more than one column".into(),
Some(span),
None,
Vec::new(),
));
return Err(ShellError::GenericError {
error: "Error using as series".into(),
msg: "dataframe has more than one column".into(),
span: Some(span),
help: None,
inner: vec![],
});
}
let series = self

View File

@ -135,14 +135,12 @@ impl NuDataFrame {
})
.collect::<Vec<Series>>();
let df_new = DataFrame::new(new_cols).map_err(|e| {
ShellError::GenericError(
"Error creating dataframe".into(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
let df_new = DataFrame::new(new_cols).map_err(|e| ShellError::GenericError {
error: "Error creating dataframe".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})?;
Ok(NuDataFrame::new(false, df_new))
@ -183,26 +181,24 @@ impl NuDataFrame {
match res {
Ok(s) => Ok(s.clone()),
Err(e) => Err({
ShellError::GenericError(
"Error appending dataframe".into(),
format!("Unable to append: {e}"),
Some(span),
None,
Vec::new(),
)
ShellError::GenericError {
error: "Error appending dataframe".into(),
msg: format!("Unable to append: {e}"),
span: Some(span),
help: None,
inner: vec![],
}
}),
}
})
.collect::<Result<Vec<Series>, ShellError>>()?;
let df_new = DataFrame::new(new_cols).map_err(|e| {
ShellError::GenericError(
"Error appending dataframe".into(),
format!("Unable to append dataframes: {e}"),
Some(span),
None,
Vec::new(),
)
let df_new = DataFrame::new(new_cols).map_err(|e| ShellError::GenericError {
error: "Error appending dataframe".into(),
msg: format!("Unable to append dataframes: {e}"),
span: Some(span),
help: None,
inner: vec![],
})?;
Ok(NuDataFrame::new(false, df_new))

View File

@ -104,14 +104,12 @@ impl NuLazyFrame {
self.lazy
.expect("No empty lazy for collect")
.collect()
.map_err(|e| {
ShellError::GenericError(
"Error collecting lazy frame".to_string(),
e.to_string(),
Some(span),
None,
Vec::new(),
)
.map_err(|e| ShellError::GenericError {
error: "Error collecting lazy frame".into(),
msg: e.to_string(),
span: Some(span),
help: None,
inner: vec![],
})
.map(|df| NuDataFrame {
df,

View File

@ -12,14 +12,12 @@ pub(crate) fn convert_columns(
// First column span
let mut col_span = columns
.first()
.ok_or_else(|| {
ShellError::GenericError(
"Empty column list".into(),
"Empty list found for command".into(),
Some(span),
None,
Vec::new(),
)
.ok_or_else(|| ShellError::GenericError {
error: "Empty column list".into(),
msg: "Empty list found for command".into(),
span: Some(span),
help: None,
inner: vec![],
})
.map(|v| v.span())?;
@ -32,13 +30,13 @@ pub(crate) fn convert_columns(
col_span = span_join(&[col_span, span]);
Ok(Spanned { item: val, span })
}
_ => Err(ShellError::GenericError(
"Incorrect column format".into(),
"Only string as column name".into(),
Some(span),
None,
Vec::new(),
)),
_ => Err(ShellError::GenericError {
error: "Incorrect column format".into(),
msg: "Only string as column name".into(),
span: Some(span),
help: None,
inner: vec![],
}),
}
})
.collect::<Result<Vec<Spanned<String>>, _>>()?;
@ -55,14 +53,12 @@ pub(crate) fn convert_columns_string(
// First column span
let mut col_span = columns
.first()
.ok_or_else(|| {
ShellError::GenericError(
"Empty column list".into(),
"Empty list found for command".into(),
Some(span),
None,
Vec::new(),
)
.ok_or_else(|| ShellError::GenericError {
error: "Empty column list".into(),
msg: "Empty list found for command".into(),
span: Some(span),
help: None,
inner: vec![],
})
.map(|v| v.span())?;
@ -75,13 +71,13 @@ pub(crate) fn convert_columns_string(
col_span = span_join(&[col_span, span]);
Ok(val)
}
_ => Err(ShellError::GenericError(
"Incorrect column format".into(),
"Only string as column name".into(),
Some(span),
None,
Vec::new(),
)),
_ => Err(ShellError::GenericError {
error: "Incorrect column format".into(),
msg: "Only string as column name".into(),
span: Some(span),
help: None,
inner: vec![],
}),
}
})
.collect::<Result<Vec<String>, _>>()?;