Skip to content

Commit 672cb16

Browse files
authored
DOC: Fix docstrings for Timestamp: unit, utcoffset, utctimetuple (#59496)
* unit, utcoffset, utctimetuple * Fix E501 line too long cython-lint
1 parent 0fadaa9 commit 672cb16

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

ci/code_checks.sh

-3
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
221221
-i "pandas.Timestamp.today SA01" \
222222
-i "pandas.Timestamp.toordinal SA01" \
223223
-i "pandas.Timestamp.tzinfo GL08" \
224-
-i "pandas.Timestamp.unit SA01" \
225-
-i "pandas.Timestamp.utcoffset SA01" \
226-
-i "pandas.Timestamp.utctimetuple SA01" \
227224
-i "pandas.Timestamp.value GL08" \
228225
-i "pandas.Timestamp.year GL08" \
229226
-i "pandas.api.extensions.ExtensionArray._pad_or_backfill PR01,RT03,SA01" \

pandas/_libs/tslibs/nattype.pyx

+34-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,24 @@ class NaTType(_NaT):
595595
utctimetuple = _make_error_func(
596596
"utctimetuple",
597597
"""
598-
Return UTC time tuple, compatible with time.localtime().
598+
Return UTC time tuple, compatible with `time.localtime()`.
599+
600+
This method converts the Timestamp to UTC and returns a time tuple
601+
containing 9 components: year, month, day, hour, minute, second,
602+
weekday, day of year, and DST flag. This is particularly useful for
603+
converting a Timestamp to a format compatible with time module functions.
604+
605+
Returns
606+
-------
607+
time.struct_time
608+
A time.struct_time object representing the UTC time.
609+
610+
See Also
611+
--------
612+
datetime.datetime.utctimetuple :
613+
Return UTC time tuple, compatible with time.localtime().
614+
Timestamp.timetuple : Return time tuple of local time.
615+
time.struct_time : Time tuple structure used by time functions.
599616
600617
Examples
601618
--------
@@ -612,6 +629,22 @@ class NaTType(_NaT):
612629
"""
613630
Return utc offset.
614631
632+
This method returns the difference between UTC and the local time
633+
as a `timedelta` object. It is useful for understanding the time
634+
difference between the current timezone and UTC.
635+
636+
Returns
637+
--------
638+
timedelta
639+
The difference between UTC and the local time as a `timedelta` object.
640+
641+
See Also
642+
--------
643+
datetime.datetime.utcoffset :
644+
Standard library method to get the UTC offset of a datetime object.
645+
Timestamp.tzname : Return the name of the timezone.
646+
Timestamp.dst : Return the daylight saving time (DST) adjustment.
647+
615648
Examples
616649
--------
617650
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')

pandas/_libs/tslibs/timestamps.pyx

+56-1
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,28 @@ cdef class _Timestamp(ABCTimestamp):
254254
"""
255255
The abbreviation associated with self._creso.
256256

257+
This property returns a string representing the time unit of the Timestamp's
258+
resolution. It corresponds to the smallest time unit that can be represented
259+
by this Timestamp object. The possible values are:
260+
- 's' (second)
261+
- 'ms' (millisecond)
262+
- 'us' (microsecond)
263+
- 'ns' (nanosecond)
264+
265+
Returns
266+
-------
267+
str
268+
A string abbreviation of the Timestamp's resolution unit:
269+
- 's' for second
270+
- 'ms' for millisecond
271+
- 'us' for microsecond
272+
- 'ns' for nanosecond
273+
274+
See Also
275+
--------
276+
Timestamp.resolution : Return resolution of the Timestamp.
277+
Timedelta : A duration expressing the difference between two dates or times.
278+
257279
Examples
258280
--------
259281
>>> pd.Timestamp("2020-01-01 12:34:56").unit
@@ -1771,6 +1793,22 @@ class Timestamp(_Timestamp):
17711793
"""
17721794
Return utc offset.
17731795
1796+
This method returns the difference between UTC and the local time
1797+
as a `timedelta` object. It is useful for understanding the time
1798+
difference between the current timezone and UTC.
1799+
1800+
Returns
1801+
--------
1802+
timedelta
1803+
The difference between UTC and the local time as a `timedelta` object.
1804+
1805+
See Also
1806+
--------
1807+
datetime.datetime.utcoffset :
1808+
Standard library method to get the UTC offset of a datetime object.
1809+
Timestamp.tzname : Return the name of the timezone.
1810+
Timestamp.dst : Return the daylight saving time (DST) adjustment.
1811+
17741812
Examples
17751813
--------
17761814
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
@@ -1783,7 +1821,24 @@ class Timestamp(_Timestamp):
17831821

17841822
def utctimetuple(self):
17851823
"""
1786-
Return UTC time tuple, compatible with time.localtime().
1824+
Return UTC time tuple, compatible with `time.localtime()`.
1825+
1826+
This method converts the Timestamp to UTC and returns a time tuple
1827+
containing 9 components: year, month, day, hour, minute, second,
1828+
weekday, day of year, and DST flag. This is particularly useful for
1829+
converting a Timestamp to a format compatible with time module functions.
1830+
1831+
Returns
1832+
-------
1833+
time.struct_time
1834+
A time.struct_time object representing the UTC time.
1835+
1836+
See Also
1837+
--------
1838+
datetime.datetime.utctimetuple :
1839+
Return UTC time tuple, compatible with time.localtime().
1840+
Timestamp.timetuple : Return time tuple of local time.
1841+
time.struct_time : Time tuple structure used by time functions.
17871842
17881843
Examples
17891844
--------

0 commit comments

Comments
 (0)