Skip to content

Commit 29ef928

Browse files
committed
cr suggestion
1 parent 061d6f0 commit 29ef928

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

native/explorer/src/datatypes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ impl ExDecimal {
644644
}
645645

646646
pub fn scale(self) -> usize {
647+
// A positive `exp` represents an integer. Polars requires `scale == 0`
648+
// for integers. The case where `exp > 0` is handled by `.signed_coef`.
647649
if self.exp > 0 {
648650
0
649651
} else {

native/explorer/src/series/from_list.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,17 @@ pub fn s_from_list_decimal(
240240
})
241241
}
242242

243-
TermType::Map => {
244-
match item.decode::<ExDecimal>() {
245-
Ok(ex_decimal) => ex_decimal
246-
.signed_coef()
247-
.map(|coef| AnyValue::Decimal(coef, ex_decimal.scale())),
248-
Err(error) => Err(ExplorerError::Other(format!(
243+
TermType::Map => item
244+
.decode::<ExDecimal>()
245+
.map_err(|error| {
246+
ExplorerError::Other(format!(
249247
"cannot decode a valid decimal from term; check that `coef` fits into an `i128`. error: {error:?}"
250-
))),
251-
}
252-
}
248+
))
249+
})
250+
.and_then(|ex_decimal| {
251+
ex_decimal.signed_coef().map(|coef| AnyValue::Decimal(coef, ex_decimal.scale()))
252+
}),
253+
253254
TermType::Atom => Ok(AnyValue::Null),
254255

255256
TermType::Float => item

0 commit comments

Comments
 (0)