Skip to content

Commit ae37506

Browse files
ncknelsonyuanx749
andauthored
DOC: Add GL08 for pandas.Timestamp.tzinfo (#61100)
* Fixed code styling * Update pandas/_libs/tslibs/timestamps.pyx Co-authored-by: Xiao Yuan <[email protected]> * Update pandas/_libs/tslibs/timestamps.pyx Co-authored-by: Xiao Yuan <[email protected]> --------- Co-authored-by: Xiao Yuan <[email protected]>
1 parent 71e6166 commit ae37506

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ci/code_checks.sh

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7575
-i "pandas.Timestamp.max PR02" \
7676
-i "pandas.Timestamp.min PR02" \
7777
-i "pandas.Timestamp.resolution PR02" \
78-
-i "pandas.Timestamp.tzinfo GL08" \
7978
-i "pandas.core.groupby.DataFrameGroupBy.plot PR02" \
8079
-i "pandas.core.groupby.SeriesGroupBy.plot PR02" \
8180
-i "pandas.core.resample.Resampler.quantile PR01,PR07" \

pandas/_libs/tslibs/timestamps.pyx

+28
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,34 @@ class Timestamp(_Timestamp):
22082208
"""
22092209
return super().tzname()
22102210
2211+
@property
2212+
def tzinfo(self):
2213+
"""
2214+
Returns the timezone info of the Timestamp.
2215+
2216+
This property returns a `datetime.tzinfo` object if the Timestamp
2217+
is timezone-aware. If the Timestamp has no timezone, it returns `None`.
2218+
If the Timestamp is in UTC or a fixed-offset timezone,
2219+
it returns `datetime.timezone`. If the Timestamp uses an
2220+
IANA timezone (e.g., "America/New_York"), it returns `zoneinfo.ZoneInfo`.
2221+
2222+
See Also
2223+
--------
2224+
Timestamp.tz : Alias for `tzinfo`, may return a `zoneinfo.ZoneInfo` object.
2225+
Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone.
2226+
Timestamp.tz_localize : Localize the Timestamp to a specific timezone.
2227+
2228+
Examples
2229+
--------
2230+
>>> ts = pd.Timestamp("2023-01-01 12:00:00", tz="UTC")
2231+
>>> ts.tzinfo
2232+
datetime.timezone.utc
2233+
2234+
>>> ts_naive = pd.Timestamp("2023-01-01 12:00:00")
2235+
>>> ts_naive.tzinfo
2236+
"""
2237+
return super().tzinfo
2238+
22112239
def utcoffset(self):
22122240
"""
22132241
Return utc offset.

0 commit comments

Comments
 (0)