diff --git a/polars/polars-arrow/src/kernels/mod.rs b/polars/polars-arrow/src/kernels/mod.rs index 02ba262ec635..7af6d99b6fcf 100644 --- a/polars/polars-arrow/src/kernels/mod.rs +++ b/polars/polars-arrow/src/kernels/mod.rs @@ -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)] diff --git a/polars/polars-arrow/src/kernels/time.rs b/polars/polars-arrow/src/kernels/time.rs index b6ecaec4eeb8..8277b7fdcebd 100644 --- a/polars/polars-arrow/src/kernels/time.rs +++ b/polars/polars-arrow/src/kernels/time.rs @@ -91,7 +91,7 @@ fn convert_to_timestamp( } #[cfg(feature = "timezones")] -pub fn replace_timezone( +pub fn replace_time_zone( arr: &PrimitiveArray, tu: TimeUnit, from: &str, diff --git a/polars/polars-core/src/chunked_array/temporal/datetime.rs b/polars/polars-core/src/chunked_array/temporal/datetime.rs index b118e2b3773f..67767e03569b 100644 --- a/polars/polars-core/src/chunked_array/temporal/datetime.rs +++ b/polars/polars-core/src/chunked_array/temporal/datetime.rs @@ -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::*; @@ -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::>()?; let out = unsafe { ChunkedArray::from_chunks(self.name(), chunks) }; diff --git a/polars/polars-lazy/polars-plan/src/dsl/dt.rs b/polars/polars-lazy/polars-plan/src/dsl/dt.rs index dcae5d9333da..f237a2c02c4b 100644 --- a/polars/polars-lazy/polars-plan/src/dsl/dt.rs +++ b/polars/polars-lazy/polars-plan/src/dsl/dt.rs @@ -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 @@ -283,11 +272,9 @@ impl DateLikeNameSpace { time_zone: Option, use_earliest: Option, ) -> 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 { diff --git a/polars/polars-lazy/polars-plan/src/dsl/function_expr/datetime.rs b/polars/polars-lazy/polars-plan/src/dsl/function_expr/datetime.rs index 89f5f431065d..e139db859a69 100644 --- a/polars/polars-lazy/polars-plan/src/dsl/function_expr/datetime.rs +++ b/polars/polars-lazy/polars-plan/src/dsl/function_expr/datetime.rs @@ -42,9 +42,7 @@ pub enum TemporalFunction { DSTOffset, Round(String, String), #[cfg(feature = "timezones")] - CastTimezone(Option, Option), - #[cfg(feature = "timezones")] - TzLocalize(TimeZone), + ReplaceTimeZone(Option, Option), DateRange { every: Duration, closed: ClosedWindow, @@ -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"), @@ -325,7 +321,7 @@ pub(super) fn round(s: &Series, every: &str, offset: &str) -> PolarsResult, use_earliest: Option, @@ -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 { - 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()) -} diff --git a/polars/polars-lazy/polars-plan/src/dsl/function_expr/mod.rs b/polars/polars-lazy/polars-plan/src/dsl/function_expr/mod.rs index 96475ac1f688..01182d8b46c5 100644 --- a/polars/polars-lazy/polars-plan/src/dsl/function_expr/mod.rs +++ b/polars/polars-lazy/polars-plan/src/dsl/function_expr/mod.rs @@ -709,7 +709,6 @@ impl From for SpecialEq> { } #[cfg(feature = "temporal")] -#[allow(deprecated)] // tz_localize impl From for SpecialEq> { fn from(func: TemporalFunction) -> Self { use TemporalFunction::*; @@ -746,11 +745,9 @@ impl From for SpecialEq> { 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, diff --git a/polars/polars-lazy/polars-plan/src/dsl/function_expr/schema.rs b/polars/polars-lazy/polars-plan/src/dsl/function_expr/schema.rs index cf32c7e9b959..30fc812d399b 100644 --- a/polars/polars-lazy/polars-plan/src/dsl/function_expr/schema.rs +++ b/polars/polars-lazy/polars-plan/src/dsl/function_expr/schema.rs @@ -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: _, diff --git a/py-polars/src/expr/datetime.rs b/py-polars/src/expr/datetime.rs index 7e446bbc2687..2369b0b93eee 100644 --- a/py-polars/src/expr/datetime.rs +++ b/py-polars/src/expr/datetime.rs @@ -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) -> Self { self.inner .clone() diff --git a/py-polars/tests/unit/datatypes/test_temporal.py b/py-polars/tests/unit/datatypes/test_temporal.py index 03fb712f46f4..8c354719b2c1 100644 --- a/py-polars/tests/unit/datatypes/test_temporal.py +++ b/py-polars/tests/unit/datatypes/test_temporal.py @@ -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") @@ -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,