Skip to content

Commit

Permalink
Fix negative decimal e-notation parsing (#6729)
Browse files Browse the repository at this point in the history
  • Loading branch information
gruuya authored Nov 14, 2024
1 parent 3ee5048 commit 1d580ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 22 additions & 6 deletions arrow-cast/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,19 +841,20 @@ pub fn parse_decimal<T: DecimalType>(
let base = T::Native::usize_as(10);

let bs = s.as_bytes();
let (bs, negative) = match bs.first() {
Some(b'-') => (&bs[1..], true),
Some(b'+') => (&bs[1..], false),
_ => (bs, false),
let (signed, negative) = match bs.first() {
Some(b'-') => (true, true),
Some(b'+') => (true, false),
_ => (false, false),
};

if bs.is_empty() {
if bs.is_empty() || signed && bs.len() == 1 {
return Err(ArrowError::ParseError(format!(
"can't parse the string value {s} to decimal"
)));
}

let mut bs = bs.iter().enumerate();
// Iterate over the raw input bytes, skipping the sign if any
let mut bs = bs.iter().enumerate().skip(signed as usize);

let mut is_e_notation = false;

Expand Down Expand Up @@ -2679,6 +2680,21 @@ mod tests {
0i128,
15,
),
(
"-1e3",
-1000000000i128,
6,
),
(
"+1e3",
1000000000i128,
6,
),
(
"-1e31",
-10000000000000000000000000000000000000i128,
6,
),
];
for (s, i, scale) in edge_tests_128 {
let result_128 = parse_decimal::<Decimal128Type>(s, 38, scale);
Expand Down
2 changes: 1 addition & 1 deletion arrow-select/src/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn zip(
"all arrays should have the same length".into(),
));
}
if truthy_is_scalar && truthy.len() != 1 {
if falsy_is_scalar && falsy.len() != 1 {
return Err(ArrowError::InvalidArgumentError(
"scalar arrays must have 1 element".into(),
));
Expand Down

0 comments on commit 1d580ec

Please sign in to comment.