Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOC: Fix docstrings for Timestamp: unit, utcoffset, utctimetuple #59496

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Timestamp.today SA01" \
-i "pandas.Timestamp.toordinal SA01" \
-i "pandas.Timestamp.tzinfo GL08" \
-i "pandas.Timestamp.unit SA01" \
-i "pandas.Timestamp.utcoffset SA01" \
-i "pandas.Timestamp.utctimetuple SA01" \
-i "pandas.Timestamp.value GL08" \
-i "pandas.Timestamp.year GL08" \
-i "pandas.api.extensions.ExtensionArray._pad_or_backfill PR01,RT03,SA01" \
Expand Down
35 changes: 34 additions & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,24 @@ class NaTType(_NaT):
utctimetuple = _make_error_func(
"utctimetuple",
"""
Return UTC time tuple, compatible with time.localtime().
Return UTC time tuple, compatible with `time.localtime()`.

This method converts the Timestamp to UTC and returns a time tuple
containing 9 components: year, month, day, hour, minute, second,
weekday, day of year, and DST flag. This is particularly useful for
converting a Timestamp to a format compatible with time module functions.

Returns
-------
time.struct_time
A time.struct_time object representing the UTC time.

See Also
--------
datetime.datetime.utctimetuple :
Return UTC time tuple, compatible with time.localtime().
Timestamp.timetuple : Return time tuple of local time.
time.struct_time : Time tuple structure used by time functions.

Examples
--------
Expand All @@ -612,6 +629,22 @@ class NaTType(_NaT):
"""
Return utc offset.

This method returns the difference between UTC and the local time
as a `timedelta` object. It is useful for understanding the time
difference between the current timezone and UTC.

Returns
--------
timedelta
The difference between UTC and the local time as a `timedelta` object.

See Also
--------
datetime.datetime.utcoffset :
Standard library method to get the UTC offset of a datetime object.
Timestamp.tzname : Return the name of the timezone.
Timestamp.dst : Return the daylight saving time (DST) adjustment.

Examples
--------
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
Expand Down
57 changes: 56 additions & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,28 @@ cdef class _Timestamp(ABCTimestamp):
"""
The abbreviation associated with self._creso.

This property returns a string representing the time unit of the Timestamp's
resolution. It corresponds to the smallest time unit that can be represented
by this Timestamp object. The possible values are:
- 's' (second)
- 'ms' (millisecond)
- 'us' (microsecond)
- 'ns' (nanosecond)

Returns
-------
str
A string abbreviation of the Timestamp's resolution unit:
- 's' for second
- 'ms' for millisecond
- 'us' for microsecond
- 'ns' for nanosecond

See Also
--------
Timestamp.resolution : Return resolution of the Timestamp.
Timedelta : A duration expressing the difference between two dates or times.

Examples
--------
>>> pd.Timestamp("2020-01-01 12:34:56").unit
Expand Down Expand Up @@ -1771,6 +1793,22 @@ class Timestamp(_Timestamp):
"""
Return utc offset.

This method returns the difference between UTC and the local time
as a `timedelta` object. It is useful for understanding the time
difference between the current timezone and UTC.

Returns
--------
timedelta
The difference between UTC and the local time as a `timedelta` object.

See Also
--------
datetime.datetime.utcoffset :
Standard library method to get the UTC offset of a datetime object.
Timestamp.tzname : Return the name of the timezone.
Timestamp.dst : Return the daylight saving time (DST) adjustment.

Examples
--------
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
Expand All @@ -1783,7 +1821,24 @@ class Timestamp(_Timestamp):

def utctimetuple(self):
"""
Return UTC time tuple, compatible with time.localtime().
Return UTC time tuple, compatible with `time.localtime()`.

This method converts the Timestamp to UTC and returns a time tuple
containing 9 components: year, month, day, hour, minute, second,
weekday, day of year, and DST flag. This is particularly useful for
converting a Timestamp to a format compatible with time module functions.

Returns
-------
time.struct_time
A time.struct_time object representing the UTC time.

See Also
--------
datetime.datetime.utctimetuple :
Return UTC time tuple, compatible with time.localtime().
Timestamp.timetuple : Return time tuple of local time.
time.struct_time : Time tuple structure used by time functions.

Examples
--------
Expand Down