Skip to content

Commit

Permalink
feat: add DataType::Decimal128
Browse files Browse the repository at this point in the history
  • Loading branch information
plaflamme committed Jan 31, 2023
1 parent b803b6d commit 0d0a898
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions polars/polars-core/src/datatypes/dtype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub enum DataType {
Int64,
Float32,
Float64,
#[cfg(feature = "dtype-i128")]
/// Fixed point decimal type with precision and scale.
/// This is backed by 128 bits which allows for 38 significant digits.
Decimal128(Option<(usize, usize)>),
/// String data
Utf8,
#[cfg(feature = "dtype-binary")]
Expand Down Expand Up @@ -208,6 +212,8 @@ impl DataType {
Int64 => ArrowDataType::Int64,
Float32 => ArrowDataType::Float32,
Float64 => ArrowDataType::Float64,
#[cfg(feature = "dtype-i128")]
Decimal128(_) => todo!(),
Utf8 => ArrowDataType::LargeUtf8,
#[cfg(feature = "dtype-binary")]
Binary => ArrowDataType::LargeBinary,
Expand Down Expand Up @@ -261,6 +267,8 @@ impl Display for DataType {
DataType::Int64 => "i64",
DataType::Float32 => "f32",
DataType::Float64 => "f64",
#[cfg(feature = "dtype-i128")]
DataType::Decimal128(_) => "i128",
DataType::Utf8 => "str",
#[cfg(feature = "dtype-binary")]
DataType::Binary => "binary",
Expand Down
13 changes: 11 additions & 2 deletions polars/polars-core/src/datatypes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ impl_polars_datatype!(Int8Type, Int8, i8);
impl_polars_datatype!(Int16Type, Int16, i16);
impl_polars_datatype!(Int32Type, Int32, i32);
impl_polars_datatype!(Int64Type, Int64, i64);
#[cfg(feature = "dtype-i128")]
impl_polars_datatype!(Int128Type, Unknown, i128);
impl_polars_datatype!(Float32Type, Float32, f32);
impl_polars_datatype!(Float64Type, Float64, f64);
impl_polars_datatype!(DateType, Date, i32);
Expand Down Expand Up @@ -120,6 +118,17 @@ impl PolarsDataType for ListType {
}
}

#[cfg(feature = "dtype-i128")]
pub struct Int128Type {}

#[cfg(feature = "dtype-i128")]
impl PolarsDataType for Int128Type {
fn get_dtype() -> DataType {
// we cannot know precision/scale statically
DataType::Decimal128(None)
}
}

#[cfg(feature = "object")]
pub struct ObjectType<T>(T);
#[cfg(feature = "object")]
Expand Down
1 change: 1 addition & 0 deletions py-polars/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ impl ToPyObject for Wrap<DataType> {
DataType::UInt64 => pl.getattr("UInt64").unwrap().into(),
DataType::Float32 => pl.getattr("Float32").unwrap().into(),
DataType::Float64 => pl.getattr("Float64").unwrap().into(),
DataType::Decimal128(_) => todo!(),
DataType::Boolean => pl.getattr("Boolean").unwrap().into(),
DataType::Utf8 => pl.getattr("Utf8").unwrap().into(),
DataType::Binary => pl.getattr("Binary").unwrap().into(),
Expand Down
1 change: 1 addition & 0 deletions py-polars/src/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl From<&DataType> for PyDataType {
DataType::UInt64 => UInt64,
DataType::Float32 => Float32,
DataType::Float64 => Float64,
DataType::Decimal128(_) => todo!(),
DataType::Boolean => Bool,
DataType::Utf8 => Utf8,
DataType::Binary => Binary,
Expand Down
1 change: 1 addition & 0 deletions py-polars/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ impl PySeries {
DataType::Int64 => PyList::new(py, series.i64().unwrap()),
DataType::Float32 => PyList::new(py, series.f32().unwrap()),
DataType::Float64 => PyList::new(py, series.f64().unwrap()),
DataType::Decimal128(_) => todo!(),
DataType::Categorical(_) => {
PyList::new(py, series.categorical().unwrap().iter_str())
}
Expand Down

0 comments on commit 0d0a898

Please sign in to comment.