Skip to content

Commit

Permalink
remove time64 dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 29, 2021
1 parent 6631e9d commit ee865c1
Show file tree
Hide file tree
Showing 28 changed files with 42 additions and 479 deletions.
2 changes: 0 additions & 2 deletions polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ private = []

# all opt-in datatypes
dtype-full = [
"dtype-time64-ns",
"dtype-date32",
"dtype-date64",
"dtype-i8",
Expand All @@ -118,7 +117,6 @@ dtype-slim = [
]

# opt-in datatypes for Series
dtype-time64-ns = ["polars-core/dtype-time64-ns"]
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
6 changes: 5 additions & 1 deletion polars/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ test-doc:
cargo test -p polars-lazy -p polars-io -p polars-core -p polars-arrow --doc


pre-commit: fmt clippy clippy-default
pre-commit: fmt clippy clippy-default


check-features:
cargo hack check --each-feature --no-dev-deps --features private
5 changes: 2 additions & 3 deletions polars/polars-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ moment = []


# opt-in datatypes for Series
dtype-time64-ns = []
dtype-date32 = []
dtype-date64 = []
dtype-date32 = ["temporal"]
dtype-date64 = ["temporal"]
dtype-i8 = []
dtype-i16 = []
dtype-u8 = []
Expand Down
4 changes: 0 additions & 4 deletions polars/polars-core/src/chunked_array/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ macro_rules! cast_with_dtype {
Date32 => ChunkCast::cast::<Date32Type>($self).map(|ca| ca.into_series()),
#[cfg(feature = "dtype-date64")]
Date64 => ChunkCast::cast::<Date64Type>($self).map(|ca| ca.into_series()),
#[cfg(feature = "dtype-time64-ns")]
Time64(TimeUnit::Nanosecond) => {
ChunkCast::cast::<Time64NanosecondType>($self).map(|ca| ca.into_series())
}
List(_) => ChunkCast::cast::<ListType>($self).map(|ca| ca.into_series()),
#[cfg(feature = "dtype-categorical")]
Categorical => ChunkCast::cast::<CategoricalType>($self).map(|ca| ca.into_series()),
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/categorical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl From<&CategoricalChunked> for DictionaryArray<i64> {
#[cfg(test)]
mod test {
use super::*;
use crate::{reset_string_cache, SINGLE_LOCK};
use crate::{reset_string_cache, toggle_string_cache, SINGLE_LOCK};
use std::convert::TryFrom;

#[test]
Expand Down
6 changes: 5 additions & 1 deletion polars/polars-core/src/chunked_array/kernels/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
pub(crate) mod take;
#[cfg(feature = "temporal")]
#[cfg(any(
feature = "temporal",
feature = "dtype-date64",
feature = "dtype-date32"
))]
#[cfg_attr(docsrs, doc(cfg(feature = "temporal")))]
pub mod temporal;
16 changes: 9 additions & 7 deletions polars/polars-core/src/chunked_array/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! The typed heart of every Series column.
use crate::prelude::*;
use arrow::{array::*, bitmap::Bitmap, datatypes::TimeUnit};
use arrow::{array::*, bitmap::Bitmap};
use itertools::Itertools;
use polars_arrow::prelude::ValueSize;
use std::convert::TryFrom;
Expand Down Expand Up @@ -30,7 +30,11 @@ mod random;
#[cfg(feature = "strings")]
#[cfg_attr(docsrs, doc(cfg(feature = "strings")))]
pub mod strings;
#[cfg(feature = "temporal")]
#[cfg(any(
feature = "temporal",
feature = "dtype-date64",
feature = "dtype-date32"
))]
#[cfg_attr(docsrs, doc(cfg(feature = "temporal")))]
pub mod temporal;
mod trusted_len;
Expand Down Expand Up @@ -231,7 +235,7 @@ impl<T> ChunkedArray<T> {
} else {
use DataType::*;
match (self.dtype(), series.dtype()) {
(Int64, Date64) | (Int32, Date32) | (Int64, Time64(_)) => {
(Int64, Date64) | (Int32, Date32) => {
let ca = &*(series_trait as *const dyn SeriesTrait as *const ChunkedArray<T>);
Ok(ca)
}
Expand Down Expand Up @@ -577,12 +581,10 @@ where
DataType::Int64 => downcast_and_pack!(Int64Array, Int64),
DataType::Float32 => downcast_and_pack!(Float32Array, Float32),
DataType::Float64 => downcast_and_pack!(Float64Array, Float64),
#[cfg(feature = "dtype-date32")]
DataType::Date32 => downcast_and_pack!(Int32Array, Date32),
#[cfg(feature = "dtype-date64")]
DataType::Date64 => downcast_and_pack!(Int64Array, Date64),
DataType::Time64(TimeUnit::Nanosecond) => {
let v = downcast!(Int64Array);
AnyValue::Time64(v, TimeUnit::Nanosecond)
}
DataType::List(_) => {
let v: ArrayRef = downcast!(LargeListArray).into();
let s = Series::try_from(("", v));
Expand Down
2 changes: 2 additions & 0 deletions polars/polars-core/src/chunked_array/temporal/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ impl Utf8Chunked {
))
}

#[cfg(feature = "dtype-date32")]
pub fn as_date32(&self, fmt: Option<&str>) -> Result<Date32Chunked> {
let fmt = match fmt {
Some(fmt) => fmt,
Expand Down Expand Up @@ -152,6 +153,7 @@ impl Utf8Chunked {
Ok(ca)
}

#[cfg(feature = "dtype-date64")]
pub fn as_date64(&self, fmt: Option<&str>) -> Result<Date64Chunked> {
let fmt = match fmt {
Some(fmt) => fmt,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Conversion extracted from:
// https://docs.rs/arrow/1.0.0/src/arrow/array/array.rs.html#589

use chrono::{NaiveDateTime, NaiveTime};
use chrono::NaiveDateTime;

/// Number of seconds in a day
pub(crate) const SECONDS_IN_DAY: i64 = 86_400;
/// Number of milliseconds in a second
const MILLISECONDS_IN_SECOND: i64 = 1_000;
/// Number of microseconds in a second
const MICROSECONDS_IN_SECOND: i64 = 1_000_000;
/// Number of nanoseconds in a second
const NANOSECONDS_IN_SECOND: i64 = 1_000_000_000;

pub(crate) fn date32_as_datetime(v: i32) -> NaiveDateTime {
NaiveDateTime::from_timestamp(v as i64 * SECONDS_IN_DAY, 0)
Expand All @@ -33,12 +31,3 @@ pub fn naive_datetime_to_date64(v: &NaiveDateTime) -> i64 {
pub fn naive_datetime_to_date32(v: &NaiveDateTime) -> i32 {
(naive_datetime_to_date64(v) / (MILLISECONDS_IN_SECOND * SECONDS_IN_DAY)) as i32
}

pub(crate) fn time64_nanosecond_as_time(v: i64) -> NaiveTime {
NaiveTime::from_num_seconds_from_midnight(
// extract seconds from nanoseconds
(v / NANOSECONDS_IN_SECOND) as u32,
// discard extracted seconds
(v % NANOSECONDS_IN_SECOND) as u32,
)
}
26 changes: 4 additions & 22 deletions polars/polars-core/src/datatypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ impl_polars_datatype!(Float64Type, Float64, f64);
impl_polars_datatype!(Date32Type, Date32, i32);
impl_polars_datatype!(Date64Type, Date64, i64);

pub struct Time64NanosecondType {}

impl PolarsDataType for Time64NanosecondType {
fn get_dtype() -> DataType {
DataType::Time64(TimeUnit::Nanosecond)
}
}

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

pub trait PolarsPrimitiveType: Send + Sync + PolarsDataType + 'static {
Expand Down Expand Up @@ -168,9 +159,6 @@ impl PolarsPrimitiveType for Date32Type {
impl PolarsPrimitiveType for Date64Type {
type Native = i64;
}
impl PolarsPrimitiveType for Time64NanosecondType {
type Native = i64;
}

macro_rules! impl_polars_numeric {
($ca:ident, $physical:ty) => {
Expand All @@ -191,7 +179,6 @@ impl_polars_numeric!(Float32Type, f32);
impl_polars_numeric!(Float64Type, f64);
impl_polars_numeric!(Date32Type, i32);
impl_polars_numeric!(Date64Type, i64);
impl_polars_numeric!(Time64NanosecondType, i64);

pub trait PolarsIntegerType: PolarsNumericType {}
impl PolarsIntegerType for UInt8Type {}
Expand All @@ -204,7 +191,6 @@ impl PolarsIntegerType for Int32Type {}
impl PolarsIntegerType for Int64Type {}
impl PolarsIntegerType for Date32Type {}
impl PolarsIntegerType for Date64Type {}
impl PolarsIntegerType for Time64NanosecondType {}

pub trait PolarsFloatType: PolarsNumericType {}
impl PolarsFloatType for Float32Type {}
Expand Down Expand Up @@ -264,12 +250,12 @@ pub enum AnyValue<'a> {
Float64(f64),
/// A 32-bit date representing the elapsed time since UNIX epoch (1970-01-01)
/// in days (32 bits).
#[cfg(feature = "dtype-date32")]
Date32(i32),
/// A 64-bit date representing the elapsed time since UNIX epoch (1970-01-01)
/// in milliseconds (64 bits).
#[cfg(feature = "dtype-date64")]
Date64(i64),
/// A 64-bit time representing the elapsed time since midnight in the unit of `TimeUnit`.
Time64(i64, TimeUnit),
/// Nested type, contains arrays that are filled with one of the datetypes.
List(Series),
#[cfg(feature = "object")]
Expand Down Expand Up @@ -389,12 +375,10 @@ impl Display for DataType {
DataType::Utf8 => "str",
DataType::Date32 => "date32(days)",
DataType::Date64 => "date64(ms)",
DataType::Time64(TimeUnit::Nanosecond) => "time64(ns)",
DataType::List(tp) => return write!(f, "list [{}]", DataType::from(tp)),
#[cfg(feature = "object")]
DataType::Object(s) => s,
DataType::Categorical => "cat",
_ => panic!("{:?} not implemented", self),
};
f.write_str(s)
}
Expand All @@ -416,9 +400,10 @@ impl PartialEq for AnyValue<'_> {
(Int64(l), Int64(r)) => l == r,
(Float32(l), Float32(r)) => l == r,
(Float64(l), Float64(r)) => l == r,
#[cfg(all(feature = "dtype-date64", feature = "dtype-date32"))]
(Date32(l), Date32(r)) => l == r,
#[cfg(all(feature = "dtype-date64", feature = "dtype-date32"))]
(Date64(l), Date64(r)) => l == r,
(Time64(l, _), Time64(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 @@ -470,7 +455,6 @@ pub enum DataType {
/// A 64-bit date representing the elapsed time since UNIX epoch (1970-01-01)
/// in milliseconds (64 bits).
Date64,
Time64(TimeUnit),
List(ArrowDataType),
#[cfg(feature = "object")]
/// A generic type that can be used in a `Series`
Expand Down Expand Up @@ -498,7 +482,6 @@ impl DataType {
Utf8 => ArrowDataType::LargeUtf8,
Date32 => ArrowDataType::Date32,
Date64 => ArrowDataType::Date64,
Time64(tu) => ArrowDataType::Time64(*tu),
List(dt) => ArrowDataType::LargeList(Box::new(arrow::datatypes::Field::new(
"",
dt.clone(),
Expand Down Expand Up @@ -706,7 +689,6 @@ impl From<&ArrowDataType> for DataType {
ArrowDataType::LargeList(f) => DataType::List(f.data_type().clone()),
ArrowDataType::Date32 => DataType::Date32,
ArrowDataType::Date64 => DataType::Date64,
ArrowDataType::Time64(TimeUnit::Nanosecond) => DataType::Time64(TimeUnit::Nanosecond),
ArrowDataType::Utf8 => DataType::Utf8,
dt => panic!("Arrow datatype {:?} not supported by Polars", dt),
}
Expand Down
6 changes: 5 additions & 1 deletion polars/polars-core/src/doc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
//! Other documentation
pub mod changelog;
#[cfg(feature = "temporal")]
#[cfg(all(
feature = "temporal",
feature = "dtype-date32",
feature = "dtype-date64"
))]
pub mod time;
22 changes: 4 additions & 18 deletions polars/polars-core/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::prelude::*;

#[cfg(feature = "temporal")]
use crate::chunked_array::temporal::{
date32_as_datetime, date64_as_datetime, time64_nanosecond_as_time,
};
#[cfg(any(feature = "dtype-date32", feature = "dtype-date64"))]
use crate::chunked_array::temporal::{date32_as_datetime, date64_as_datetime};
use num::{Num, NumCast};
use std::{
fmt,
Expand Down Expand Up @@ -304,14 +302,6 @@ impl Debug for Series {
self.name(),
"Series"
),
DataType::Time64(TimeUnit::Nanosecond) => format_array!(
limit,
f,
self.time64_nanosecond().unwrap(),
"time64(ns)",
self.name(),
"Series"
),
DataType::List(_) => format_array!(
limit,
f,
Expand Down Expand Up @@ -554,17 +544,13 @@ impl Display for AnyValue<'_> {
AnyValue::Float64(v) => fmt_float(f, width, *v),
AnyValue::Boolean(v) => write!(f, "{}", *v),
AnyValue::Utf8(v) => write!(f, "{}", format!("\"{}\"", v)),
#[cfg(feature = "temporal")]
#[cfg(feature = "dtype-date32")]
AnyValue::Date32(v) => write!(f, "{}", date32_as_datetime(*v).date()),
#[cfg(feature = "temporal")]
#[cfg(feature = "dtype-date64")]
AnyValue::Date64(v) => write!(f, "{}", date64_as_datetime(*v)),
AnyValue::Time64(v, TimeUnit::Nanosecond) => {
write!(f, "{}", time64_nanosecond_as_time(*v))
}
AnyValue::List(s) => write!(f, "{}", s.fmt_list()),
#[cfg(feature = "object")]
AnyValue::Object(_) => write!(f, "object"),
_ => unimplemented!(),
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions polars/polars-core/src/frame/groupby/pivot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ impl Series {
*self = s;
self.as_groupable_iter()
}
DataType::Time64(TimeUnit::Nanosecond) => {
let s = self.cast::<Int64Type>()?;
*self = s;
self.as_groupable_iter()
}
DataType::Utf8 => as_groupable_iter!(self.utf8().unwrap(), Utf8),
DataType::Float32 => {
let s = self.f32()?.bit_repr_small().into_series();
Expand Down
2 changes: 2 additions & 0 deletions polars/polars-core/src/frame/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ impl<'a> From<&AnyValue<'a>> for Field {
Int64(_) => Field::new("", DataType::Int64),
Float32(_) => Field::new("", DataType::Float32),
Float64(_) => Field::new("", DataType::Float64),
#[cfg(feature = "dtype-date32")]
Date32(_) => Field::new("", DataType::Date32),
#[cfg(feature = "dtype-date64")]
Date64(_) => Field::new("", DataType::Date64),
_ => unimplemented!(),
}
Expand Down
9 changes: 0 additions & 9 deletions polars/polars-core/src/serde/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ impl Serialize for Series {
ca.serialize(serializer)
} else if let Ok(ca) = self.date64() {
ca.serialize(serializer)
} else if let Ok(ca) = self.time64_nanosecond() {
ca.serialize(serializer)
} else if let Ok(ca) = self.utf8() {
ca.serialize(serializer)
} else if let Ok(ca) = self.bool() {
Expand Down Expand Up @@ -154,13 +152,6 @@ impl<'de> Deserialize<'de> for Series {
let values: Vec<Option<f64>> = map.next_value()?;
Ok(Series::new(&name, values))
}
#[cfg(feature = "dtype-time64-ns")]
DeDataType::Time64(TimeUnit::Nanosecond) => {
let values: Vec<Option<i64>> = map.next_value()?;
Ok(Series::new(&name, values)
.cast::<Time64NanosecondType>()
.unwrap())
}
DeDataType::Utf8 => {
let values: Vec<Option<&str>> = map.next_value()?;
Ok(Series::new(&name, values))
Expand Down
4 changes: 0 additions & 4 deletions polars/polars-core/src/series/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ macro_rules! impl_compare {
DataType::Float64 => lhs.f64().unwrap().$method(rhs.f64().unwrap()),
DataType::Date32 => lhs.date32().unwrap().$method(rhs.date32().unwrap()),
DataType::Date64 => lhs.date64().unwrap().$method(rhs.date64().unwrap()),
DataType::Time64(TimeUnit::Nanosecond) => lhs
.time64_nanosecond()
.unwrap()
.$method(rhs.time64_nanosecond().unwrap()),
DataType::List(_) => lhs.list().unwrap().$method(rhs.list().unwrap()),
_ => unimplemented!(),
}
Expand Down

0 comments on commit ee865c1

Please sign in to comment.