From dd651040973aee0d4bff45194995074b4f8506e5 Mon Sep 17 00:00:00 2001 From: Nicholas Nelson Date: Tue, 11 Mar 2025 01:49:56 +0000 Subject: [PATCH 1/3] Fixed code styling --- ci/code_checks.sh | 1 - pandas/_libs/tslibs/timestamps.pyx | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 6ce43725fecc9..2410f19d32a66 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -78,7 +78,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.max PR02" \ -i "pandas.Timestamp.min PR02" \ -i "pandas.Timestamp.resolution PR02" \ - -i "pandas.Timestamp.tzinfo GL08" \ -i "pandas.core.groupby.DataFrameGroupBy.plot PR02" \ -i "pandas.core.groupby.SeriesGroupBy.plot PR02" \ -i "pandas.core.resample.Resampler.quantile PR01,PR07" \ diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 452ba0fe869ee..64ce2bb676d4a 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -2208,6 +2208,35 @@ class Timestamp(_Timestamp): """ return super().tzname() + @property + def tzinfo(self): + """ + Returns the timezone info of the Timestamp. + + This property returns a `datetime.tzinfo` object if the Timestamp + is timezone-aware. If the Timestamp has no timezone, it returns `None`. + If the Timestamp is in UTC or a fixed-offset timezone, + it returns `datetime.timezone`. If the Timestamp uses an + IANA timezone (e.g., "America/New_York"), it returns `zoneinfo.ZoneInfo`. + + See Also + -------- + Timestamp.tz : Alias for `tzinfo`, may return a `zoneinfo.ZoneInfo` object. + Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone. + Timestamp.tz_localize : Localize the Timestamp to a specific timezone. + + Examples + -------- + >>> ts = pd.Timestamp("2023-01-01 12:00:00", tz="UTC") + >>> ts.tzinfo + UTC + + >>> ts_naive = pd.Timestamp("2023-01-01 12:00:00") + >>> ts_naive.tzinfo + None + """ + return super().tzinfo + def utcoffset(self): """ Return utc offset. From 4bf159cac1dc00149a88ce5401f87f243d6537ed Mon Sep 17 00:00:00 2001 From: ncknelson <147194262+ncknelson@users.noreply.github.com> Date: Wed, 12 Mar 2025 00:20:23 -0700 Subject: [PATCH 2/3] Update pandas/_libs/tslibs/timestamps.pyx Co-authored-by: Xiao Yuan --- pandas/_libs/tslibs/timestamps.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 64ce2bb676d4a..7aeeb838b4421 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -2229,7 +2229,7 @@ class Timestamp(_Timestamp): -------- >>> ts = pd.Timestamp("2023-01-01 12:00:00", tz="UTC") >>> ts.tzinfo - UTC + datetime.timezone.utc >>> ts_naive = pd.Timestamp("2023-01-01 12:00:00") >>> ts_naive.tzinfo From 2fba797dabaefae8798fa8b5ff66ec39a0e07edd Mon Sep 17 00:00:00 2001 From: ncknelson <147194262+ncknelson@users.noreply.github.com> Date: Sat, 15 Mar 2025 20:24:56 -0700 Subject: [PATCH 3/3] Update pandas/_libs/tslibs/timestamps.pyx Co-authored-by: Xiao Yuan --- pandas/_libs/tslibs/timestamps.pyx | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index 7aeeb838b4421..23197b9a55afc 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -2233,7 +2233,6 @@ class Timestamp(_Timestamp): >>> ts_naive = pd.Timestamp("2023-01-01 12:00:00") >>> ts_naive.tzinfo - None """ return super().tzinfo