Skip to content

Commit

Permalink
chore(rust)!: remove deprecate tz_localize, name CastTimezone to Repl…
Browse files Browse the repository at this point in the history
…aceTimeZone (#10070)
  • Loading branch information
MarcoGorelli authored Jul 25, 2023
1 parent f8adbb7 commit b15859b
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 56 deletions.
2 changes: 1 addition & 1 deletion polars/polars-arrow/src/kernels/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub mod take_agg;
mod time;

#[cfg(feature = "timezones")]
pub use time::replace_timezone;
pub use time::replace_time_zone;

/// Internal state of [SlicesIterator]
#[derive(Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion polars/polars-arrow/src/kernels/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn convert_to_timestamp(
}

#[cfg(feature = "timezones")]
pub fn replace_timezone(
pub fn replace_time_zone(
arr: &PrimitiveArray<i64>,
tu: TimeUnit,
from: &str,
Expand Down
4 changes: 2 additions & 2 deletions polars/polars-core/src/chunked_array/temporal/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use chrono::TimeZone as TimeZoneTrait;
#[cfg(feature = "timezones")]
use chrono_tz::Tz;
#[cfg(feature = "timezones")]
use polars_arrow::kernels::replace_timezone;
use polars_arrow::kernels::replace_time_zone;

use super::conversion::{datetime_to_timestamp_ms, datetime_to_timestamp_ns};
use super::*;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl DatetimeChunked {
let chunks = self
.downcast_iter()
.map(|arr| {
replace_timezone(arr, self.time_unit().to_arrow(), from, to, use_earliest)
replace_time_zone(arr, self.time_unit().to_arrow(), from, to, use_earliest)
})
.collect::<PolarsResult<_>>()?;
let out = unsafe { ChunkedArray::from_chunks(self.name(), chunks) };
Expand Down
19 changes: 3 additions & 16 deletions polars/polars-lazy/polars-plan/src/dsl/dt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ impl DateLikeNameSpace {
)
}

/// Localize tz-naive Datetime Series to tz-aware Datetime Series.
//
// This method takes a naive Datetime Series and makes this time zone aware.
// It does not move the time to another time zone.
#[cfg(feature = "timezones")]
#[deprecated(note = "use replace_time_zone")]
pub fn tz_localize(self, tz: TimeZone) -> Expr {
self.0
.map_private(FunctionExpr::TemporalExpr(TemporalFunction::TzLocalize(tz)))
}

/// Get the year of a Date/Datetime
pub fn year(self) -> Expr {
self.0
Expand Down Expand Up @@ -283,11 +272,9 @@ impl DateLikeNameSpace {
time_zone: Option<TimeZone>,
use_earliest: Option<bool>,
) -> Expr {
self.0
.map_private(FunctionExpr::TemporalExpr(TemporalFunction::CastTimezone(
time_zone,
use_earliest,
)))
self.0.map_private(FunctionExpr::TemporalExpr(
TemporalFunction::ReplaceTimeZone(time_zone, use_earliest),
))
}

pub fn combine(self, time: Expr, tu: TimeUnit) -> Expr {
Expand Down
23 changes: 3 additions & 20 deletions polars/polars-lazy/polars-plan/src/dsl/function_expr/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ pub enum TemporalFunction {
DSTOffset,
Round(String, String),
#[cfg(feature = "timezones")]
CastTimezone(Option<TimeZone>, Option<bool>),
#[cfg(feature = "timezones")]
TzLocalize(TimeZone),
ReplaceTimeZone(Option<TimeZone>, Option<bool>),
DateRange {
every: Duration,
closed: ClosedWindow,
Expand Down Expand Up @@ -102,9 +100,7 @@ impl Display for TemporalFunction {
DSTOffset => "dst_offset",
Round(..) => "round",
#[cfg(feature = "timezones")]
CastTimezone(_, _) => "replace_timezone",
#[cfg(feature = "timezones")]
TzLocalize(_) => "tz_localize",
ReplaceTimeZone(_, _) => "replace_time_zone",
DateRange { .. } => return write!(f, "date_range"),
DateRanges { .. } => return write!(f, "date_ranges"),
TimeRange { .. } => return write!(f, "time_range"),
Expand Down Expand Up @@ -325,7 +321,7 @@ pub(super) fn round(s: &Series, every: &str, offset: &str) -> PolarsResult<Serie
}

#[cfg(feature = "timezones")]
pub(super) fn replace_timezone(
pub(super) fn replace_time_zone(
s: &Series,
time_zone: Option<&str>,
use_earliest: Option<bool>,
Expand All @@ -334,16 +330,3 @@ pub(super) fn replace_timezone(
ca.replace_time_zone(time_zone, use_earliest)
.map(|ca| ca.into_series())
}

#[cfg(feature = "timezones")]
#[deprecated(note = "use replace_time_zone")]
pub(super) fn tz_localize(s: &Series, tz: &str) -> PolarsResult<Series> {
let ca = s.datetime()?.clone();
polars_ensure!(
ca.time_zone().as_ref().map_or(true, |tz| tz.is_empty()),
ComputeError:
"cannot localize a tz-aware datetime \
(consider using 'dt.convert_time_zone' or 'dt.replace_time_zone')"
);
Ok(ca.replace_time_zone(Some(tz), None)?.into_series())
}
7 changes: 2 additions & 5 deletions polars/polars-lazy/polars-plan/src/dsl/function_expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,6 @@ impl From<BinaryFunction> for SpecialEq<Arc<dyn SeriesUdf>> {
}

#[cfg(feature = "temporal")]
#[allow(deprecated)] // tz_localize
impl From<TemporalFunction> for SpecialEq<Arc<dyn SeriesUdf>> {
fn from(func: TemporalFunction) -> Self {
use TemporalFunction::*;
Expand Down Expand Up @@ -746,11 +745,9 @@ impl From<TemporalFunction> for SpecialEq<Arc<dyn SeriesUdf>> {
DSTOffset => map!(datetime::dst_offset),
Round(every, offset) => map!(datetime::round, &every, &offset),
#[cfg(feature = "timezones")]
CastTimezone(tz, use_earliest) => {
map!(datetime::replace_timezone, tz.as_deref(), use_earliest)
ReplaceTimeZone(tz, use_earliest) => {
map!(datetime::replace_time_zone, tz.as_deref(), use_earliest)
}
#[cfg(feature = "timezones")]
TzLocalize(tz) => map!(datetime::tz_localize, &tz),
Combine(tu) => map_as_slice!(temporal::combine, tu),
DateRange {
every,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ impl FunctionExpr {
DSTOffset => DataType::Duration(TimeUnit::Milliseconds),
Round(..) => mapper.with_same_dtype().unwrap().dtype,
#[cfg(feature = "timezones")]
CastTimezone(tz, _use_earliest) => {
ReplaceTimeZone(tz, _use_earliest) => {
return mapper.map_datetime_dtype_timezone(tz.as_ref())
}
#[cfg(feature = "timezones")]
TzLocalize(tz) => return mapper.map_datetime_dtype_timezone(Some(tz)),
DateRange {
every,
closed: _,
Expand Down
6 changes: 0 additions & 6 deletions py-polars/src/expr/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ impl PyExpr {
.into()
}

#[cfg(feature = "timezones")]
#[allow(deprecated)]
fn dt_tz_localize(&self, time_zone: String) -> Self {
self.inner.clone().dt().tz_localize(time_zone).into()
}

fn dt_truncate(&self, every: String, offset: String, use_earliest: Option<bool>) -> Self {
self.inner
.clone()
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/unit/datatypes/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1891,7 +1891,7 @@ def test_iso_year() -> None:
assert pl.Series([date(2022, 1, 1)]).dt.iso_year()[0] == 2021


def test_replace_timezone() -> None:
def test_replace_time_zone() -> None:
ny = ZoneInfo("America/New_York")
assert pl.DataFrame({"a": [datetime(2022, 9, 25, 14)]}).with_columns(
pl.col("a").dt.replace_time_zone("America/New_York").alias("b")
Expand All @@ -1910,7 +1910,7 @@ def test_replace_timezone() -> None:
)
@pytest.mark.parametrize("from_tz", ["Asia/Seoul", None])
@pytest.mark.parametrize("time_unit", ["ms", "us", "ns"])
def test_replace_timezone_from_to(
def test_replace_time_zone_from_to(
from_tz: str,
to_tz: str,
tzinfo: timezone | ZoneInfo,
Expand Down

0 comments on commit b15859b

Please sign in to comment.