Skip to content

Commit

Permalink
Add Decimal workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jun 14, 2024
1 parent 9da204a commit 8679207
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 4 additions & 3 deletions crates/polars-core/src/datatypes/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub enum DataType {
Int64,
Float32,
Float64,
#[cfg(feature = "dtype-decimal")]
/// Fixed point decimal type optional precision and non-negative scale.
/// This is backed by a signed 128-bit integer which allows for up to 38 significant digits.
#[cfg(feature = "dtype-decimal")]
Decimal(Option<usize>, Option<usize>), // precision/scale; scale being None means "infer"
/// String data
String,
Expand All @@ -76,14 +76,14 @@ pub enum DataType {
Array(Box<DataType>, usize),
/// A nested list with a variable size in each row
List(Box<DataType>),
#[cfg(feature = "object")]
/// A generic type that can be used in a `Series`
/// &'static str can be used to determine/set inner type
#[cfg(feature = "object")]
Object(&'static str, Option<Arc<ObjectRegistry>>),
Null,
#[cfg(feature = "dtype-categorical")]
// The RevMapping has the internal state.
// This is ignored with comparisons, hashing etc.
#[cfg(feature = "dtype-categorical")]
Categorical(Option<Arc<RevMapping>>, CategoricalOrdering),
#[cfg(feature = "dtype-categorical")]
Enum(Option<Arc<RevMapping>>, CategoricalOrdering),
Expand Down Expand Up @@ -140,6 +140,7 @@ impl PartialEq for DataType {
(UnknownKind::Int(_), UnknownKind::Int(_)) => true,
_ => l == r,
},
// TODO: Add Decimal equality
_ => std::mem::discriminant(self) == std::mem::discriminant(other),
}
}
Expand Down
9 changes: 9 additions & 0 deletions crates/polars-core/src/series/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,17 @@ impl Series {
let dtype = if strict {
get_first_non_null_dtype(values)
} else {
// Currently does not work correctly for Decimal because equality is not implemented.
any_values_to_supertype(values)?
};

// TODO: Remove this when Decimal data type equality is implemented.
#[cfg(feature = "dtype-decimal")]
if !strict && dtype.is_decimal() {
let dtype = DataType::Decimal(None, None);
return Self::from_any_values_and_dtype(name, values, &dtype, strict);
}

Self::from_any_values_and_dtype(name, values, &dtype, strict)
}

Expand Down
4 changes: 1 addition & 3 deletions py-polars/src/series/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,7 @@ impl PySeries {

#[staticmethod]
fn new_decimal(name: &str, values: &Bound<PyAny>, strict: bool) -> PyResult<Self> {
// Create a fake dtype with a placeholder "none" scale, to be inferred later.
let dtype = DataType::Decimal(None, None);
Self::new_from_any_values_and_dtype(name, values, Wrap(dtype), strict)
Self::new_from_any_values(name, values, strict)
}

#[staticmethod]
Expand Down

0 comments on commit 8679207

Please sign in to comment.