Skip to content

Commit

Permalink
fix polars timezone switching
Browse files Browse the repository at this point in the history
  • Loading branch information
polinaeterna committed Jan 17, 2025
1 parent 2f27846 commit f9d7a8a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion services/worker/src/worker/statistics_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f9d7a8a

Please sign in to comment.