From d55ab1e44944ee0fac15ea3931cda4a96632b677 Mon Sep 17 00:00:00 2001 From: lixiliu <36629962+lixiliu@users.noreply.github.com> Date: Tue, 12 Nov 2024 14:37:29 -0700 Subject: [PATCH 1/2] fix iter_timestamps() --- src/chronify/time_configs.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/chronify/time_configs.py b/src/chronify/time_configs.py index 0d1c4ab..0e6636b 100644 --- a/src/chronify/time_configs.py +++ b/src/chronify/time_configs.py @@ -3,6 +3,7 @@ import logging from datetime import datetime, timedelta from typing import Any, Union, Literal +from zoneinfo import ZoneInfo import pandas as pd from pydantic import ( @@ -184,14 +185,22 @@ def is_time_zone_naive(self) -> bool: return self.start.tzinfo is None def list_timestamps_from_dataframe(self, df: pd.DataFrame) -> list[datetime]: - return df[self.time_column].to_list() + return df[self.time_column].drop_duplicates().to_list() def list_time_columns(self) -> list[str]: return [self.time_column] def iter_timestamps(self) -> Generator[datetime, None, None]: for i in range(self.length): - cur = adjust_timestamp_by_dst_offset(self.start + i * self.resolution, self.resolution) + if self.is_time_zone_naive(): + cur = adjust_timestamp_by_dst_offset( + self.start + i * self.resolution, self.resolution + ) + else: + tz = self.start.tzinfo + # always step in standard time + cur_utc = self.start.astimezone(ZoneInfo("UTC")) + i * self.resolution + cur = adjust_timestamp_by_dst_offset(cur_utc.astimezone(tz), self.resolution) month = cur.month day = cur.day if not ( From f8bc1f2d3eee61fe48b68a6d01a291ab3baa00d2 Mon Sep 17 00:00:00 2001 From: lixiliu <36629962+lixiliu@users.noreply.github.com> Date: Wed, 13 Nov 2024 17:02:58 -0700 Subject: [PATCH 2/2] undo drop_duplicates() --- src/chronify/time_configs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chronify/time_configs.py b/src/chronify/time_configs.py index 0e6636b..647b35e 100644 --- a/src/chronify/time_configs.py +++ b/src/chronify/time_configs.py @@ -185,7 +185,7 @@ def is_time_zone_naive(self) -> bool: return self.start.tzinfo is None def list_timestamps_from_dataframe(self, df: pd.DataFrame) -> list[datetime]: - return df[self.time_column].drop_duplicates().to_list() + return df[self.time_column].to_list() def list_time_columns(self) -> list[str]: return [self.time_column]