Skip to content

Commit

Permalink
fix: Missing timezone metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kukushkin <kukushkin.anton@gmail.com>
  • Loading branch information
kukushking committed Feb 19, 2024
1 parent 0d95026 commit 95fd843
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions awswrangler/_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ def _apply_timezone(df: pd.DataFrame, metadata: dict[str, Any]) -> pd.DataFrame:
else:
continue
if col_name in df.columns and c["pandas_type"] == "datetimetz":
timezone: datetime.tzinfo = pa.lib.string_to_tzinfo(c["metadata"]["timezone"])
_logger.debug("applying timezone (%s) on column %s", timezone, col_name)
if hasattr(df[col_name].dtype, "tz") is False:
df[col_name] = df[col_name].dt.tz_localize(tz="UTC")
if timezone is not None and timezone != pytz.UTC and hasattr(df[col_name].dt, "tz_convert"):
df[col_name] = df[col_name].dt.tz_convert(tz=timezone)
column_metadata: dict[str, Any] = c["metadata"] if c.get("metadata") else {}
timezone_str: str | None = column_metadata.get("timezone")
if timezone_str:
timezone: datetime.tzinfo = pa.lib.string_to_tzinfo(timezone_str)
_logger.debug("applying timezone (%s) on column %s", timezone, col_name)
if hasattr(df[col_name].dtype, "tz") is False:
df[col_name] = df[col_name].dt.tz_localize(tz="UTC")
if timezone is not None and timezone != pytz.UTC and hasattr(df[col_name].dt, "tz_convert"):
df[col_name] = df[col_name].dt.tz_convert(tz=timezone)
return df


Expand Down

0 comments on commit 95fd843

Please sign in to comment.