Skip to content

Commit

Permalink
remove duration dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 15, 2021
1 parent bb3de77 commit a392cf0
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 431 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ members = [
"polars/polars-lazy",
]

[patch.crates-io]
packed_simd_2 = { git = 'https://github.com/rust-lang/packed_simd', rev = "e57c7ba11386147e6d2cbad7c88f376aab4bdc86" }
#[patch.crates-io]
#packed_simd_2 = { git = 'https://github.com/rust-lang/packed_simd', rev = "e57c7ba11386147e6d2cbad7c88f376aab4bdc86" }
4 changes: 0 additions & 4 deletions polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ private = []
# all opt-in datatypes
dtype-full = [
"dtype-time64-ns",
"dtype-duration-ns",
"dtype-duration-ms",
"dtype-date32",
"dtype-date64",
"dtype-i8",
Expand All @@ -119,8 +117,6 @@ dtype-slim = [

# opt-in datatypes for Series
dtype-time64-ns = ["polars-core/dtype-time64-ns"]
dtype-duration-ns = ["polars-core/dtype-duration-ns"]
dtype-duration-ms = ["polars-core/dtype-duration-ms"]
dtype-date32 = ["polars-core/dtype-date32", "polars-lazy/dtype-date32"]
dtype-date64 = ["polars-core/dtype-date64", "polars-lazy/dtype-date64"]
dtype-i8 = ["polars-core/dtype-i8", "polars-lazy/dtype-i8"]
Expand Down
2 changes: 0 additions & 2 deletions polars/polars-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ moment = []

# opt-in datatypes for Series
dtype-time64-ns = []
dtype-duration-ns = []
dtype-duration-ms = []
dtype-date32 = []
dtype-date64 = []
dtype-i8 = []
Expand Down
32 changes: 3 additions & 29 deletions polars/polars-core/src/chunked_array/cast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Implementations of the ChunkCast Trait.
use crate::chunked_array::builder::CategoricalChunkedBuilder;
use crate::chunked_array::kernels::{cast_logical, cast_physical};
use crate::chunked_array::kernels::cast_physical;
use crate::prelude::*;
use arrow::array::Array;
use arrow::compute::cast;
Expand All @@ -24,18 +24,6 @@ where
Ok(ChunkedArray::new_from_chunks(ca.field.name(), chunks))
}

macro_rules! cast_from_dtype {
($self: expr, $kernel:expr, $dtype: expr) => {{
let chunks = $self
.downcast_iter()
.into_iter()
.map(|arr| $kernel(arr, &$dtype))
.collect();

Ok(ChunkedArray::new_from_chunks($self.field.name(), chunks))
}};
}

fn cast_from_dtype<N, T>(chunked: &ChunkedArray<T>, dtype: DataType) -> Result<ChunkedArray<N>>
where
N: PolarsNumericType,
Expand Down Expand Up @@ -81,14 +69,6 @@ macro_rules! cast_with_dtype {
Time64(TimeUnit::Nanosecond) => {
ChunkCast::cast::<Time64NanosecondType>($self).map(|ca| ca.into_series())
}
#[cfg(feature = "dtype-duration-ns")]
Duration(TimeUnit::Nanosecond) => {
ChunkCast::cast::<DurationNanosecondType>($self).map(|ca| ca.into_series())
}
#[cfg(feature = "dtype-duration-ms")]
Duration(TimeUnit::Millisecond) => {
ChunkCast::cast::<DurationMillisecondType>($self).map(|ca| ca.into_series())
}
List(_) => ChunkCast::cast::<ListType>($self).map(|ca| ca.into_series()),
Categorical => ChunkCast::cast::<CategoricalType>($self).map(|ca| ca.into_series()),
dt => Err(PolarsError::ComputeError(
Expand Down Expand Up @@ -163,21 +143,15 @@ where
ca.field = Arc::new(Field::new(ca.name(), DataType::Categorical));
return Ok(ca);
}
// the underlying datatype is i64 so we transmute array
(Duration(_), Int64) => {
cast_from_dtype!(self, cast_logical, Int64)
}
// paths not supported by arrow kernel
// to float32
(Duration(_), Float32) | (Date32, Float32) | (Date64, Float32) => {
(Date32, Float32) | (Date64, Float32) => {
cast_from_dtype::<Float32Type, _>(self, Float32)?.cast::<N>()
}
// to float64
(Duration(_), Float64) | (Date32, Float64) | (Date64, Float64) => {
(Date32, Float64) | (Date64, Float64) => {
cast_from_dtype::<Float64Type, _>(self, Float64)?.cast::<N>()
}
// to uint64
(Duration(_), UInt64) => cast_from_dtype::<UInt64Type, _>(self, UInt64)?.cast::<N>(),
// to date64
(Int32, Date64) | (Float64, Date64) | (Float32, Date64) => {
cast_from_dtype::<Date64Type, _>(self, Date64)?.cast::<N>()
Expand Down
12 changes: 0 additions & 12 deletions polars/polars-core/src/chunked_array/kernels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,6 @@ use num::Float;
use polars_arrow::prelude::default_arrays::FromData;
use std::sync::Arc;

/// Casts a `PrimitiveArray` from its logical type to a logical type compatible
/// with its physical type.
/// This operation is `O(1)`
/// # Panics
/// Panics if `data_type` is not supported by type `T`
pub(crate) fn cast_logical<T: NativeType>(arr: &PrimitiveArray<T>, data_type: &DataType) -> ArrayRef
where
T: NativeType,
{
Arc::new(arr.clone().to(data_type.to_arrow()))
}

/// Casts a `PrimitiveArray` to a different physical type and logical type.
/// This operation is `O(N)`
/// Values that do not fit in the new physical type are converted to nulls.
Expand Down
10 changes: 1 addition & 9 deletions polars/polars-core/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl<T> ChunkedArray<T> {
} else {
use DataType::*;
match (self.dtype(), series.dtype()) {
(Int64, Date64) | (Int32, Date32) | (Int64, Duration(_)) | (Int64, Time64(_)) => {
(Int64, Date64) | (Int32, Date32) | (Int64, Time64(_)) => {
let ca = &*(series_trait as *const dyn SeriesTrait as *const ChunkedArray<T>);
Ok(ca)
}
Expand Down Expand Up @@ -575,14 +575,6 @@ where
let v = downcast!(Int64Array);
AnyValue::Time64(v, TimeUnit::Nanosecond)
}
DataType::Duration(TimeUnit::Nanosecond) => {
let v = downcast!(Int64Array);
AnyValue::Duration(v, TimeUnit::Nanosecond)
}
DataType::Duration(TimeUnit::Millisecond) => {
let v = downcast!(Int64Array);
AnyValue::Duration(v, TimeUnit::Millisecond)
}
DataType::List(_) => {
let v: ArrayRef = downcast!(LargeListArray).into();
let s = Series::try_from(("", v));
Expand Down
4 changes: 0 additions & 4 deletions polars/polars-core/src/chunked_array/temporal/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,6 @@ impl AsNaiveDate for Date32Chunked {
}
}

pub trait AsDuration<T> {
fn as_duration(&self) -> ChunkedArray<T>;
}

impl AsNaiveTime for Time64NanosecondChunked {
fn as_naive_time(&self) -> Vec<Option<NaiveTime>> {
self.into_iter()
Expand Down
3 changes: 1 addition & 2 deletions polars/polars-core/src/chunked_array/temporal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
pub mod conversion;
pub(crate) mod conversions_utils;
pub use self::conversion::{
AsDuration, AsNaiveDate, AsNaiveDateTime, AsNaiveTime, FromNaiveDate, FromNaiveDateTime,
FromNaiveTime,
AsNaiveDate, AsNaiveDateTime, AsNaiveTime, FromNaiveDate, FromNaiveDateTime, FromNaiveTime,
};
pub(crate) use self::conversions_utils::*;
use chrono::NaiveDateTime;
Expand Down
41 changes: 0 additions & 41 deletions polars/polars-core/src/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,6 @@ impl PolarsDataType for Time64NanosecondType {
}
}

pub struct DurationNanosecondType {}

impl PolarsDataType for DurationNanosecondType {
fn get_dtype() -> DataType {
DataType::Duration(TimeUnit::Nanosecond)
}
}

pub struct DurationMillisecondType {}

impl PolarsDataType for DurationMillisecondType {
fn get_dtype() -> DataType {
DataType::Duration(TimeUnit::Millisecond)
}
}

impl PolarsDataType for Utf8Type {
fn get_dtype() -> DataType {
DataType::Utf8
Expand Down Expand Up @@ -142,8 +126,6 @@ pub type Float64Chunked = ChunkedArray<Float64Type>;
pub type Utf8Chunked = ChunkedArray<Utf8Type>;
pub type Date32Chunked = ChunkedArray<Date32Type>;
pub type Date64Chunked = ChunkedArray<Date64Type>;
pub type DurationNanosecondChunked = ChunkedArray<DurationNanosecondType>;
pub type DurationMillisecondChunked = ChunkedArray<DurationMillisecondType>;
pub type Time64NanosecondChunked = ChunkedArray<Time64NanosecondType>;
pub type CategoricalChunked = ChunkedArray<CategoricalType>;

Expand Down Expand Up @@ -189,12 +171,6 @@ impl PolarsPrimitiveType for Date64Type {
impl PolarsPrimitiveType for Time64NanosecondType {
type Native = i64;
}
impl PolarsPrimitiveType for DurationNanosecondType {
type Native = i64;
}
impl PolarsPrimitiveType for DurationMillisecondType {
type Native = i64;
}

macro_rules! impl_polars_numeric {
($ca:ident, $physical:ty) => {
Expand All @@ -216,8 +192,6 @@ impl_polars_numeric!(Float64Type, f64);
impl_polars_numeric!(Date32Type, i32);
impl_polars_numeric!(Date64Type, i64);
impl_polars_numeric!(Time64NanosecondType, i64);
impl_polars_numeric!(DurationNanosecondType, i64);
impl_polars_numeric!(DurationMillisecondType, i64);

pub trait PolarsIntegerType: PolarsNumericType {}
impl PolarsIntegerType for UInt8Type {}
Expand All @@ -231,8 +205,6 @@ impl PolarsIntegerType for Int64Type {}
impl PolarsIntegerType for Date32Type {}
impl PolarsIntegerType for Date64Type {}
impl PolarsIntegerType for Time64NanosecondType {}
impl PolarsIntegerType for DurationNanosecondType {}
impl PolarsIntegerType for DurationMillisecondType {}

pub trait PolarsFloatType: PolarsNumericType {}
impl PolarsFloatType for Float32Type {}
Expand Down Expand Up @@ -298,8 +270,6 @@ pub enum AnyValue<'a> {
Date64(i64),
/// A 64-bit time representing the elapsed time since midnight in the unit of `TimeUnit`.
Time64(i64, TimeUnit),
/// A 32-bit time representing the elapsed time since midnight in the unit of `TimeUnit`.
Duration(i64, TimeUnit),
/// Nested type, contains arrays that are filled with one of the datetypes.
List(Series),
#[cfg(feature = "object")]
Expand Down Expand Up @@ -420,8 +390,6 @@ impl Display for DataType {
DataType::Date32 => "date32(days)",
DataType::Date64 => "date64(ms)",
DataType::Time64(TimeUnit::Nanosecond) => "time64(ns)",
DataType::Duration(TimeUnit::Nanosecond) => "duration(ns)",
DataType::Duration(TimeUnit::Millisecond) => "duration(ms)",
DataType::List(tp) => return write!(f, "list [{}]", DataType::from(tp)),
#[cfg(feature = "object")]
DataType::Object(s) => s,
Expand Down Expand Up @@ -451,7 +419,6 @@ impl PartialEq for AnyValue<'_> {
(Date32(l), Date32(r)) => l == r,
(Date64(l), Date64(r)) => l == r,
(Time64(l, _), Time64(r, _)) => l == r,
(Duration(l, _), Duration(r, _)) => l == r,
(Boolean(l), Boolean(r)) => l == r,
(List(_), List(_)) => panic!("eq between list series not supported"),
#[cfg(feature = "object")]
Expand Down Expand Up @@ -505,7 +472,6 @@ pub enum DataType {
Date64,
Time64(TimeUnit),
List(ArrowDataType),
Duration(TimeUnit),
#[cfg(feature = "object")]
/// A generic type that can be used in a `Series`
/// &'static str can be used to determine/set inner type
Expand Down Expand Up @@ -538,7 +504,6 @@ impl DataType {
dt.clone(),
true,
))),
Duration(tu) => ArrowDataType::Duration(*tu),
Null => ArrowDataType::Null,
#[cfg(feature = "object")]
Object(_) => panic!("cannot convert object to arrow"),
Expand Down Expand Up @@ -740,12 +705,6 @@ impl From<&ArrowDataType> for DataType {
ArrowDataType::Date32 => DataType::Date32,
ArrowDataType::Date64 => DataType::Date64,
ArrowDataType::Time64(TimeUnit::Nanosecond) => DataType::Time64(TimeUnit::Nanosecond),
ArrowDataType::Duration(TimeUnit::Nanosecond) => {
DataType::Duration(TimeUnit::Nanosecond)
}
ArrowDataType::Duration(TimeUnit::Millisecond) => {
DataType::Duration(TimeUnit::Millisecond)
}
ArrowDataType::Utf8 => DataType::Utf8,
dt => panic!("Arrow datatype {:?} not supported by Polars", dt),
}
Expand Down
18 changes: 0 additions & 18 deletions polars/polars-core/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,6 @@ impl Debug for Series {
self.name(),
"Series"
),
DataType::Duration(TimeUnit::Nanosecond) => format_array!(
limit,
f,
self.duration_nanosecond().unwrap(),
"duration(ns)",
self.name(),
"Series"
),
DataType::Duration(TimeUnit::Millisecond) => format_array!(
limit,
f,
self.duration_millisecond().unwrap(),
"duration(ms)",
self.name(),
"Series"
),
DataType::List(_) => format_array!(
limit,
f,
Expand Down Expand Up @@ -577,8 +561,6 @@ impl Display for AnyValue<'_> {
AnyValue::Time64(v, TimeUnit::Nanosecond) => {
write!(f, "{}", time64_nanosecond_as_time(*v))
}
AnyValue::Duration(v, TimeUnit::Nanosecond) => write!(f, "{}", v),
AnyValue::Duration(v, TimeUnit::Millisecond) => write!(f, "{}", v),
AnyValue::List(s) => write!(f, "{}", s.fmt_list()),
#[cfg(feature = "object")]
AnyValue::Object(_) => write!(f, "object"),
Expand Down
8 changes: 0 additions & 8 deletions polars/polars-core/src/series/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ macro_rules! impl_compare {
.time64_nanosecond()
.unwrap()
.$method(rhs.time64_nanosecond().unwrap()),
DataType::Duration(TimeUnit::Nanosecond) => lhs
.duration_nanosecond()
.unwrap()
.$method(rhs.duration_nanosecond().unwrap()),
DataType::Duration(TimeUnit::Millisecond) => lhs
.duration_millisecond()
.unwrap()
.$method(rhs.duration_millisecond().unwrap()),
DataType::List(_) => lhs.list().unwrap().$method(rhs.list().unwrap()),
_ => unimplemented!(),
}
Expand Down

0 comments on commit a392cf0

Please sign in to comment.