Skip to content

Commit eb5ab35

Browse files
authored
Merge branch 'main' into fix/rotate-rds-certs
2 parents 45f81ed + 784978d commit eb5ab35

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

awswrangler/_arrow.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,15 @@ def _apply_timezone(df: pd.DataFrame, metadata: dict[str, Any]) -> pd.DataFrame:
7070
else:
7171
continue
7272
if col_name in df.columns and c["pandas_type"] == "datetimetz":
73-
timezone: datetime.tzinfo = pa.lib.string_to_tzinfo(c["metadata"]["timezone"])
74-
_logger.debug("applying timezone (%s) on column %s", timezone, col_name)
75-
if hasattr(df[col_name].dtype, "tz") is False:
76-
df[col_name] = df[col_name].dt.tz_localize(tz="UTC")
77-
if timezone is not None and timezone != pytz.UTC and hasattr(df[col_name].dt, "tz_convert"):
78-
df[col_name] = df[col_name].dt.tz_convert(tz=timezone)
73+
column_metadata: dict[str, Any] = c["metadata"] if c.get("metadata") else {}
74+
timezone_str: str | None = column_metadata.get("timezone")
75+
if timezone_str:
76+
timezone: datetime.tzinfo = pa.lib.string_to_tzinfo(timezone_str)
77+
_logger.debug("applying timezone (%s) on column %s", timezone, col_name)
78+
if hasattr(df[col_name].dtype, "tz") is False:
79+
df[col_name] = df[col_name].dt.tz_localize(tz="UTC")
80+
if timezone is not None and timezone != pytz.UTC and hasattr(df[col_name].dt, "tz_convert"):
81+
df[col_name] = df[col_name].dt.tz_convert(tz=timezone)
7982
return df
8083

8184

0 commit comments

Comments
 (0)