Skip to content

Commit 2190bac

Browse files
authored
Merge branch 'main' into upgrade-ray-2.30
2 parents fc6ecff + f646ed3 commit 2190bac

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

awswrangler/_arrow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ def _apply_timezone(df: pd.DataFrame, metadata: dict[str, Any]) -> pd.DataFrame:
7272
if col_name in df.columns and c["pandas_type"] == "datetimetz":
7373
column_metadata: dict[str, Any] = c["metadata"] if c.get("metadata") else {}
7474
timezone_str: str | None = column_metadata.get("timezone")
75+
7576
if timezone_str:
7677
timezone: datetime.tzinfo = pa.lib.string_to_tzinfo(timezone_str)
7778
_logger.debug("applying timezone (%s) on column %s", timezone, col_name)
78-
if hasattr(df[col_name].dtype, "tz") is False:
79+
80+
if hasattr(df[col_name].dt, "tz") is False or df[col_name].dt.tz is None:
7981
df[col_name] = df[col_name].dt.tz_localize(tz="UTC")
82+
8083
if timezone is not None and timezone != pytz.UTC and hasattr(df[col_name].dt, "tz_convert"):
8184
df[col_name] = df[col_name].dt.tz_convert(tz=timezone)
85+
8286
return df
8387

8488

tests/unit/test_s3_parquet.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,13 +645,17 @@ def test_timezone_raw_values(path):
645645
df["c3"] = pd.to_datetime(datetime(2011, 11, 4, 0, 5, 23, tzinfo=timezone(-timedelta(seconds=14400))))
646646
df["c4"] = pd.to_datetime(datetime(2011, 11, 4, 0, 5, 23, tzinfo=timezone(timedelta(hours=-8))))
647647
wr.s3.to_parquet(partition_cols=["par"], df=df, path=path, dataset=True, sanitize_columns=False)
648+
648649
df2 = wr.s3.read_parquet(path, dataset=True, use_threads=False, pyarrow_additional_kwargs={"ignore_metadata": True})
650+
649651
# Use pandas to read because of Modin "Internal Error: Internal and external indices on axis 1 do not match."
650652
import pandas
651653

652654
df3 = pandas.read_parquet(path)
655+
653656
df2["par"] = df2["par"].astype("string")
654657
df3["par"] = df3["par"].astype("string")
658+
655659
assert_pandas_equals(df2, df3)
656660

657661

0 commit comments

Comments
 (0)