Make arg eval lazy, remove old arg evaluation code (#3603)

* Remove old argument eval

* Merge main

* fmt

* clippy

* clippy

* clippy
This commit is contained in:
JT
2021-06-11 13:57:01 +12:00
committed by GitHub
parent c4163c3621
commit 8ac572ed27
218 changed files with 448 additions and 1075 deletions

View File

@ -97,11 +97,13 @@ impl NuDataFrame {
UntaggedValue::DataFrame(PolarsData::EagerDataFrame(df)) => Some(df),
_ => None,
})
.ok_or(ShellError::labeled_error(
"No dataframe in stream",
"no dataframe found in input stream",
span,
))
.ok_or_else(|| {
ShellError::labeled_error(
"No dataframe in stream",
"no dataframe found in input stream",
span,
)
})
}
pub fn try_from_iter<T>(iter: T, tag: &Tag) -> Result<Self, ShellError>

View File

@ -33,11 +33,13 @@ impl NuGroupBy {
UntaggedValue::DataFrame(PolarsData::GroupBy(group)) => Some(group),
_ => None,
})
.ok_or(ShellError::labeled_error(
"No groupby object in stream",
"no groupby object found in input stream",
span,
))
.ok_or_else(|| {
ShellError::labeled_error(
"No groupby object in stream",
"no groupby object found in input stream",
span,
)
})
}
pub fn to_groupby(&self) -> Result<GroupBy, ShellError> {

View File

@ -60,11 +60,13 @@ impl NuSeries {
UntaggedValue::DataFrame(PolarsData::Series(series)) => Some(series),
_ => None,
})
.ok_or(ShellError::labeled_error(
"No series in stream",
"no series found in input stream",
span,
))
.ok_or_else(|| {
ShellError::labeled_error(
"No series in stream",
"no series found in input stream",
span,
)
})
}
pub fn try_from_iter<T>(iter: T, name: Option<String>) -> Result<Self, ShellError>
@ -265,7 +267,8 @@ fn insert_value(value: Value, vec_values: &mut Vec<Value>) -> Result<(), ShellEr
// Checking that the type for the value is the same
// for the previous value in the column
if vec_values.is_empty() {
Ok(vec_values.push(value))
vec_values.push(value);
Ok(())
} else {
let prev_value = &vec_values[vec_values.len() - 1];
@ -281,7 +284,10 @@ fn insert_value(value: Value, vec_values: &mut Vec<Value>) -> Result<(), ShellEr
| (
UntaggedValue::Primitive(Primitive::String(_)),
UntaggedValue::Primitive(Primitive::String(_)),
) => Ok(vec_values.push(value)),
) => {
vec_values.push(value);
Ok(())
}
_ => Err(ShellError::labeled_error_with_secondary(
"Different values in column",
"Value with different type",

View File

@ -1287,6 +1287,12 @@ impl NamedValue {
vec![]
}
}
pub fn get_contents(&self) -> Option<&SpannedExpression> {
match self {
NamedValue::Value(_, expr) => Some(expr),
_ => None,
}
}
}
impl PrettyDebugWithSource for NamedValue {
@ -1341,6 +1347,13 @@ impl Call {
.unwrap_or(false)
}
pub fn get_flag(&self, switch: &str) -> Option<&SpannedExpression> {
self.named
.as_ref()
.and_then(|n| n.get(switch))
.and_then(|x| x.get_contents())
}
pub fn set_initial_flags(&mut self, signature: &crate::Signature) {
for (named, value) in signature.named.iter() {
if self.named.is_none() {