Skip to content

Commit

Permalink
fix: append decimal with different scale
Browse files Browse the repository at this point in the history
  • Loading branch information
flisky committed Jan 25, 2024
1 parent 32c2fb4 commit 73d70c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions crates/polars-core/src/datatypes/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ pub(crate) fn can_extend_dtype(left: &DataType, right: &DataType) -> PolarsResul
Ok(must_cast)
},
(DataType::Null, DataType::Null) => Ok(false),
#[cfg(feature = "dtype-decimal")]
(DataType::Decimal(_, s1), DataType::Decimal(_, s2)) => Ok(s1 != s2),
// Other way around we don't allow because we keep left dtype as is.
// We don't go to supertype, and we certainly don't want to cast self to null type.
(_, DataType::Null) => Ok(true),
Expand Down
20 changes: 20 additions & 0 deletions crates/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,26 @@ mod test {
assert!(s1.append(&s2).is_err())
}

#[test]
#[cfg(feature = "dtype-decimal")]
fn series_append_decimal() {
let s1 = Series::new("a", &[1.1, 2.3]).cast(&DataType::Decimal(None, Some(2))).unwrap();
let s2 = Series::new("b", &[3]).cast(&DataType::Decimal(None, Some(0))).unwrap();

{
let mut s1 = s1.clone();
s1.append(&s2).unwrap();
assert_eq!(s1.len(), 3);
assert_eq!(s1.get(2).unwrap(), AnyValue::Decimal(300, 2));
}

{
let mut s2 = s2.clone();
s2.append(&s1).unwrap();
assert_eq!(s2.get(2).unwrap(), AnyValue::Decimal(2, 0))
}
}

#[test]
fn series_slice_works() {
let series = Series::new("a", &[1i64, 2, 3, 4, 5]);
Expand Down

0 comments on commit 73d70c3

Please sign in to comment.