Skip to content

Commit

Permalink
chrono in polars_time only
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Dec 17, 2021
1 parent 5268c01 commit 2f2f448
Show file tree
Hide file tree
Showing 16 changed files with 22 additions and 21 deletions.
3 changes: 1 addition & 2 deletions polars/polars-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = "Core of the Polars DataFrame library"
simd = ["arrow/simd"]
avx512 = []
docs = []
temporal = ["chrono", "regex"]
temporal = ["regex", "polars-time"]
random = ["rand", "rand_distr"]
default = ["docs", "temporal", "performant", "private"]
lazy = ["sort_multiple"]
Expand Down Expand Up @@ -131,7 +131,6 @@ anyhow = "1.0"
# arrow = { package = "arrow2", git = "https://github.com/ritchie46/arrow2", default-features = false, features = ["compute"], branch = "fn_to" }
# arrow = { package = "arrow2", version = "0.8", default-features = false, features = ["compute"] }

chrono = { version = "0.4", optional = true }
comfy-table = { version = "4.0", optional = true }
hashbrown = { version = "0.11", features = ["rayon"] }
itertools = "0.10"
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/kernels/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use arrow::compute::arity::unary;
#[cfg(feature = "dtype-time")]
use arrow::temporal_conversions::time64ns_to_time;
use arrow::temporal_conversions::{date32_to_datetime, timestamp_ns_to_datetime};
use chrono::{Datelike, NaiveDate, NaiveDateTime, Timelike};
use polars_time::export::chrono::{Datelike, NaiveDate, NaiveDateTime, Timelike};
use std::sync::Arc;

trait PolarsWeekDay {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::prelude::*;
use arrow::temporal_conversions::NANOSECONDS;
use polars_time::Window;
use polars_time::{Duration, Window};

#[cfg(feature = "dtype-datetime")]
impl DatetimeChunked {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::prelude::AnyValue;
#[cfg(feature = "dtype-time")]
use arrow::temporal_conversions::time64ns_to_time;
use arrow::temporal_conversions::{timestamp_ms_to_datetime, NANOSECONDS};
use chrono::{NaiveDateTime, NaiveTime};
use polars_time::export::chrono::{NaiveDateTime, NaiveTime};

/// Number of seconds in a day
pub(crate) const SECONDS_IN_DAY: i64 = 86_400;
Expand Down
5 changes: 3 additions & 2 deletions polars/polars-core/src/chunked_array/temporal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
//! Traits and utilities for temporal data.
#[cfg(feature = "temporal")]
pub mod buckets;
pub mod conversion;
#[cfg(feature = "dtype-date")]
mod date;
#[cfg(feature = "dtype-datetime")]
mod datetime;
#[cfg(feature = "dtype-time")]
mod time;
pub mod timedelta;
mod utf8;

pub use self::conversion::*;
use crate::chunked_array::kernels::temporal::*;
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use polars_time::export::chrono::{NaiveDate, NaiveDateTime, NaiveTime};

pub fn unix_time() -> NaiveDateTime {
NaiveDateTime::from_timestamp(0, 0)
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/chunked_array/temporal/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::chunked_array::kernels::temporal::{
time_to_hour, time_to_minute, time_to_nanosecond, time_to_second,
};
use crate::prelude::*;
use crate::utils::chrono::Timelike;
use crate::utils::NoNull;
use arrow::temporal_conversions::{time64ns_to_time, NANOSECONDS};
use polars_time::export::chrono::Timelike;

pub(crate) fn time_to_time64ns(time: &NaiveTime) -> i64 {
time.second() as i64 * NANOSECONDS + time.nanosecond() as i64
Expand Down
1 change: 1 addition & 0 deletions polars/polars-core/src/chunked_array/temporal/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;
#[cfg(feature = "dtype-time")]
use crate::chunked_array::temporal::time::time_to_time64ns;
use crate::prelude::*;
use polars_time::export::chrono;

#[cfg(feature = "dtype-time")]
fn time_pattern<F, K>(val: &str, convert: F) -> Option<&'static str>
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-core/src/export.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub use arrow;
#[cfg(all(feature = "private", feature = "temporal"))]
pub use chrono;
pub use polars_time::export::chrono;
2 changes: 1 addition & 1 deletion polars/polars-core/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ impl Display for AnyValue<'_> {
AnyValue::Datetime(v) => write!(f, "{}", timestamp_ns_to_datetime(*v)),
#[cfg(feature = "dtype-time")]
AnyValue::Time(_) => {
let nt: chrono::NaiveTime = self.into();
let nt: polars_time::export::chrono::NaiveTime = self.into();
write!(f, "{}", nt)
}
#[cfg(feature = "dtype-categorical")]
Expand Down
11 changes: 6 additions & 5 deletions polars/polars-core/src/frame/groupby/dynamic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::frame::groupby::GroupTuples;
use crate::prelude::*;
use crate::POOL;
use polars_time::groupby::ClosedWindow;
use polars_time::{Duration, Window};
use rayon::prelude::*;
use crate::POOL;

#[derive(Clone, Debug)]
pub struct DynamicGroupOptions {
Expand Down Expand Up @@ -75,7 +75,8 @@ impl DataFrame {
.iter()
.map(|g| {
let offset = g.0;
let dt = unsafe { dt.take_unchecked((g.1.iter().map(|i| *i as usize)).into()) };
let dt =
unsafe { dt.take_unchecked((g.1.iter().map(|i| *i as usize)).into()) };
let vals = dt.downcast_iter().next().unwrap();
let ts = vals.values().as_slice();
let (mut sub_groups, lower, upper) = polars_time::groupby::groupby(
Expand Down Expand Up @@ -113,7 +114,9 @@ impl DataFrame {
.par_iter()
.map(|g| {
let offset = g.0;
let dt = unsafe { dt.take_unchecked((g.1.iter().map(|i| *i as usize)).into()) };
let dt = unsafe {
dt.take_unchecked((g.1.iter().map(|i| *i as usize)).into())
};
let vals = dt.downcast_iter().next().unwrap();
let ts = vals.values().as_slice();
let (mut sub_groups, _, _) = polars_time::groupby::groupby(
Expand All @@ -134,9 +137,7 @@ impl DataFrame {
.flatten()
.collect::<Vec<_>>()
})

}

};

// Safety:
Expand Down
2 changes: 0 additions & 2 deletions polars/polars-core/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ pub(crate) mod series;
use crate::prelude::*;
use crate::POOL;
pub use arrow;
#[cfg(feature = "temporal")]
pub use chrono;
pub use num_cpus;
pub use polars_arrow::utils::TrustMyLength;
pub use polars_arrow::utils::*;
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-lazy/src/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use polars_core::export::arrow::{array::BooleanArray, bitmap::MutableBitmap};
use polars_core::prelude::*;

#[cfg(feature = "temporal")]
use polars_core::utils::chrono::{NaiveDate, NaiveDateTime};
use polars_core::export::chrono::{NaiveDate, NaiveDateTime};
use std::fmt::{Debug, Formatter};
use std::ops::{BitAnd, BitOr, Deref};
use std::{
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-lazy/src/logical_plan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use std::{
use ahash::RandomState;
use itertools::Itertools;

use polars_core::prelude::*;
#[cfg_attr(docsrs, doc(cfg(feature = "temporal")))]
#[cfg(feature = "temporal")]
use polars_core::utils::chrono::NaiveDateTime;
use polars_core::export::chrono::NaiveDateTime;
use polars_core::prelude::*;
#[cfg(feature = "csv-file")]
use polars_io::csv_core::utils::infer_file_schema;
#[cfg(feature = "parquet")]
Expand Down
1 change: 1 addition & 0 deletions polars/polars-time/src/export.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use chrono;
1 change: 1 addition & 0 deletions polars/polars-time/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
mod bounds;
mod calendar;
mod duration;
pub mod export;
pub mod groupby;
#[cfg(test)]
mod test;
Expand Down
1 change: 0 additions & 1 deletion py-polars/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2f2f448

Please sign in to comment.