From f9d7a8a7f8db8c89468609029ecc2604a46c8e9e Mon Sep 17 00:00:00 2001 From: polinaeterna Date: Fri, 17 Jan 2025 12:41:33 +0100 Subject: [PATCH] fix polars timezone switching --- services/worker/src/worker/statistics_utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/worker/src/worker/statistics_utils.py b/services/worker/src/worker/statistics_utils.py index 590d9286b..1c9afe0c2 100644 --- a/services/worker/src/worker/statistics_utils.py +++ b/services/worker/src/worker/statistics_utils.py @@ -801,13 +801,14 @@ def _compute_statistics( ) original_timezone = None if isinstance(data[column_name].dtype, pl.String): - original_timezone = get_timezone(data[column_name][0]) # let polars identify format itself. provide manually in case of error try: + original_timezone = get_timezone(data[column_name][0]) data = data.with_columns(pl.col(column_name).str.to_datetime()) except pl.ComputeError: datetime_format = cls.get_format(data, column_name) data = data.with_columns(pl.col(column_name).str.to_datetime(format=datetime_format)) + original_timezone = None min_date: datetime.datetime = data[column_name].min() # type: ignore # mypy infers type of datetime column .min() incorrectly timedelta_column_name = f"{column_name}_timedelta"