-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat[rust]: add iso_year and make dt computed attributes serde (#4873)
- Loading branch information
Showing
14 changed files
with
309 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#[cfg(feature = "serde")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use super::*; | ||
|
||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] | ||
#[derive(Clone, PartialEq, Debug, Eq, Hash)] | ||
pub enum TemporalFunction { | ||
Year, | ||
IsoYear, | ||
Quarter, | ||
Month, | ||
Week, | ||
WeekDay, | ||
Day, | ||
OrdinalDay, | ||
Hour, | ||
Minute, | ||
Second, | ||
NanoSecond, | ||
TimeStamp(TimeUnit), | ||
} | ||
|
||
impl Display for TemporalFunction { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
use TemporalFunction::*; | ||
let s = match self { | ||
Year => "year", | ||
IsoYear => "iso_year", | ||
Quarter => "quarter", | ||
Month => "month", | ||
Week => "week", | ||
WeekDay => "weekday", | ||
Day => "day", | ||
OrdinalDay => "ordinal_day", | ||
Hour => "hour", | ||
Minute => "minute", | ||
Second => "second", | ||
NanoSecond => "nanosecond", | ||
TimeStamp(tu) => return write!(f, "dt.timestamp({})", tu), | ||
}; | ||
write!(f, "dt.{}", s) | ||
} | ||
} | ||
|
||
pub(super) fn year(s: &Series) -> PolarsResult<Series> { | ||
s.year().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn iso_year(s: &Series) -> PolarsResult<Series> { | ||
s.iso_year().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn month(s: &Series) -> PolarsResult<Series> { | ||
s.month().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn quarter(s: &Series) -> PolarsResult<Series> { | ||
s.quarter().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn week(s: &Series) -> PolarsResult<Series> { | ||
s.week().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn weekday(s: &Series) -> PolarsResult<Series> { | ||
s.weekday().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn day(s: &Series) -> PolarsResult<Series> { | ||
s.day().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn ordinal_day(s: &Series) -> PolarsResult<Series> { | ||
s.ordinal_day().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn hour(s: &Series) -> PolarsResult<Series> { | ||
s.hour().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn minute(s: &Series) -> PolarsResult<Series> { | ||
s.minute().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn second(s: &Series) -> PolarsResult<Series> { | ||
s.second().map(|ca| ca.into_series()) | ||
} | ||
pub(super) fn nanosecond(s: &Series) -> PolarsResult<Series> { | ||
s.nanosecond().map(|ca| ca.into_series()) | ||
} | ||
|
||
pub(super) fn timestamp(s: &Series, tu: TimeUnit) -> PolarsResult<Series> { | ||
s.timestamp(tu).map(|ca| ca.into_series()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.