mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Update internal use of decimal
to float
(#10333)
# Description We made the decision that our floating point type should be referred to as `float` over `decimal`. Commands were updated by #9979 and #10320 Now make the internal codebase consistent in referring to this data type as `float`. Work for #10332 # User-Facing Changes `decimal` has been removed as a type name/symbol. Instead of ```nushell def foo [bar: decimal] decimal -> decimal {} ``` use ```nushell def foo [bar: float] float -> float {} ``` Potential effect of `SyntaxShape`'s `Display` implementation now also referring to `float` instead of `decimal` # Details - Rename `SyntaxShape::Decimal` to `Float` - Update `Display for SyntaxShape` to `float` - Update error message + fn name in dataframe code - Fix docs in command examples - Rename tests that are float specific - Update doccomment on `SyntaxShape` - Update comment in script # Tests + Formatting Updates the names of some tests
This commit is contained in:
committed by
GitHub
parent
5bd7300cd5
commit
bbf0b45c59
@ -226,7 +226,7 @@ pub(super) fn compute_series_single_value(
|
||||
compute_series_i64(&lhs, *val, <ChunkedArray<Int64Type>>::add, lhs_span)
|
||||
}
|
||||
Value::Float { val, .. } => {
|
||||
compute_series_decimal(&lhs, *val, <ChunkedArray<Float64Type>>::add, lhs_span)
|
||||
compute_series_float(&lhs, *val, <ChunkedArray<Float64Type>>::add, lhs_span)
|
||||
}
|
||||
Value::String { val, .. } => add_string_to_series(&lhs, val, lhs_span),
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
@ -242,7 +242,7 @@ pub(super) fn compute_series_single_value(
|
||||
compute_series_i64(&lhs, *val, <ChunkedArray<Int64Type>>::sub, lhs_span)
|
||||
}
|
||||
Value::Float { val, .. } => {
|
||||
compute_series_decimal(&lhs, *val, <ChunkedArray<Float64Type>>::sub, lhs_span)
|
||||
compute_series_float(&lhs, *val, <ChunkedArray<Float64Type>>::sub, lhs_span)
|
||||
}
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
@ -257,7 +257,7 @@ pub(super) fn compute_series_single_value(
|
||||
compute_series_i64(&lhs, *val, <ChunkedArray<Int64Type>>::mul, lhs_span)
|
||||
}
|
||||
Value::Float { val, .. } => {
|
||||
compute_series_decimal(&lhs, *val, <ChunkedArray<Float64Type>>::mul, lhs_span)
|
||||
compute_series_float(&lhs, *val, <ChunkedArray<Float64Type>>::mul, lhs_span)
|
||||
}
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
op_span: operator.span,
|
||||
@ -281,12 +281,7 @@ pub(super) fn compute_series_single_value(
|
||||
if val.is_zero() {
|
||||
Err(ShellError::DivisionByZero { span })
|
||||
} else {
|
||||
compute_series_decimal(
|
||||
&lhs,
|
||||
*val,
|
||||
<ChunkedArray<Float64Type>>::div,
|
||||
lhs_span,
|
||||
)
|
||||
compute_series_float(&lhs, *val, <ChunkedArray<Float64Type>>::div, lhs_span)
|
||||
}
|
||||
}
|
||||
_ => Err(ShellError::OperatorMismatch {
|
||||
@ -301,7 +296,7 @@ pub(super) fn compute_series_single_value(
|
||||
Operator::Comparison(Comparison::Equal) => match &right {
|
||||
Value::Int { val, .. } => compare_series_i64(&lhs, *val, ChunkedArray::equal, lhs_span),
|
||||
Value::Float { val, .. } => {
|
||||
compare_series_decimal(&lhs, *val, ChunkedArray::equal, lhs_span)
|
||||
compare_series_float(&lhs, *val, ChunkedArray::equal, lhs_span)
|
||||
}
|
||||
Value::String { val, .. } => {
|
||||
let equal_pattern = format!("^{}$", fancy_regex::escape(val));
|
||||
@ -323,7 +318,7 @@ pub(super) fn compute_series_single_value(
|
||||
compare_series_i64(&lhs, *val, ChunkedArray::not_equal, lhs_span)
|
||||
}
|
||||
Value::Float { val, .. } => {
|
||||
compare_series_decimal(&lhs, *val, ChunkedArray::not_equal, lhs_span)
|
||||
compare_series_float(&lhs, *val, ChunkedArray::not_equal, lhs_span)
|
||||
}
|
||||
Value::Date { val, .. } => compare_series_i64(
|
||||
&lhs,
|
||||
@ -342,7 +337,7 @@ pub(super) fn compute_series_single_value(
|
||||
Operator::Comparison(Comparison::LessThan) => match &right {
|
||||
Value::Int { val, .. } => compare_series_i64(&lhs, *val, ChunkedArray::lt, lhs_span),
|
||||
Value::Float { val, .. } => {
|
||||
compare_series_decimal(&lhs, *val, ChunkedArray::lt, lhs_span)
|
||||
compare_series_float(&lhs, *val, ChunkedArray::lt, lhs_span)
|
||||
}
|
||||
Value::Date { val, .. } => {
|
||||
compare_series_i64(&lhs, val.timestamp_millis(), ChunkedArray::lt, lhs_span)
|
||||
@ -358,7 +353,7 @@ pub(super) fn compute_series_single_value(
|
||||
Operator::Comparison(Comparison::LessThanOrEqual) => match &right {
|
||||
Value::Int { val, .. } => compare_series_i64(&lhs, *val, ChunkedArray::lt_eq, lhs_span),
|
||||
Value::Float { val, .. } => {
|
||||
compare_series_decimal(&lhs, *val, ChunkedArray::lt_eq, lhs_span)
|
||||
compare_series_float(&lhs, *val, ChunkedArray::lt_eq, lhs_span)
|
||||
}
|
||||
Value::Date { val, .. } => {
|
||||
compare_series_i64(&lhs, val.timestamp_millis(), ChunkedArray::lt_eq, lhs_span)
|
||||
@ -374,7 +369,7 @@ pub(super) fn compute_series_single_value(
|
||||
Operator::Comparison(Comparison::GreaterThan) => match &right {
|
||||
Value::Int { val, .. } => compare_series_i64(&lhs, *val, ChunkedArray::gt, lhs_span),
|
||||
Value::Float { val, .. } => {
|
||||
compare_series_decimal(&lhs, *val, ChunkedArray::gt, lhs_span)
|
||||
compare_series_float(&lhs, *val, ChunkedArray::gt, lhs_span)
|
||||
}
|
||||
Value::Date { val, .. } => {
|
||||
compare_series_i64(&lhs, val.timestamp_millis(), ChunkedArray::gt, lhs_span)
|
||||
@ -390,7 +385,7 @@ pub(super) fn compute_series_single_value(
|
||||
Operator::Comparison(Comparison::GreaterThanOrEqual) => match &right {
|
||||
Value::Int { val, .. } => compare_series_i64(&lhs, *val, ChunkedArray::gt_eq, lhs_span),
|
||||
Value::Float { val, .. } => {
|
||||
compare_series_decimal(&lhs, *val, ChunkedArray::gt_eq, lhs_span)
|
||||
compare_series_float(&lhs, *val, ChunkedArray::gt_eq, lhs_span)
|
||||
}
|
||||
Value::Date { val, .. } => {
|
||||
compare_series_i64(&lhs, val.timestamp_millis(), ChunkedArray::gt_eq, lhs_span)
|
||||
@ -514,12 +509,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_series_decimal<F>(
|
||||
series: &Series,
|
||||
val: f64,
|
||||
f: F,
|
||||
span: Span,
|
||||
) -> Result<Value, ShellError>
|
||||
fn compute_series_float<F>(series: &Series, val: f64, f: F, span: Span) -> Result<Value, ShellError>
|
||||
where
|
||||
F: Fn(ChunkedArray<Float64Type>, f64) -> ChunkedArray<Float64Type>,
|
||||
{
|
||||
@ -548,7 +538,7 @@ where
|
||||
_ => Err(ShellError::GenericError(
|
||||
"Incorrect type".into(),
|
||||
format!(
|
||||
"Series of type {} can not be used for operations with a decimal value",
|
||||
"Series of type {} can not be used for operations with a float value",
|
||||
series.dtype()
|
||||
),
|
||||
Some(span),
|
||||
@ -668,12 +658,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn compare_series_decimal<F>(
|
||||
series: &Series,
|
||||
val: f64,
|
||||
f: F,
|
||||
span: Span,
|
||||
) -> Result<Value, ShellError>
|
||||
fn compare_series_float<F>(series: &Series, val: f64, f: F, span: Span) -> Result<Value, ShellError>
|
||||
where
|
||||
F: Fn(&ChunkedArray<Float64Type>, f64) -> ChunkedArray<BooleanType>,
|
||||
{
|
||||
@ -702,7 +687,7 @@ where
|
||||
_ => Err(ShellError::GenericError(
|
||||
"Incorrect type".into(),
|
||||
format!(
|
||||
"Series of type {} can not be used for operations with a decimal value",
|
||||
"Series of type {} can not be used for operations with a float value",
|
||||
series.dtype()
|
||||
),
|
||||
Some(span),
|
||||
|
Reference in New Issue
Block a user