Skip to content

Commit 7945e56

Browse files
authored
DOC: Fix docstrings for Timestamp: strptime, timetz, to_datetime64, to_julian_date (#59569)
* strptime * strptime + timestamp * timetuple * timetz * to_datetime64 * to_julian_date * timetz * code_checks * duplicate see also
1 parent 1044cf4 commit 7945e56

File tree

3 files changed

+90
-10
lines changed

3 files changed

+90
-10
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
191191
-i "pandas.Timestamp.nanosecond GL08" \
192192
-i "pandas.Timestamp.resolution PR02" \
193193
-i "pandas.Timestamp.second GL08" \
194-
-i "pandas.Timestamp.strptime PR01,SA01" \
195-
-i "pandas.Timestamp.timetz SA01" \
196-
-i "pandas.Timestamp.to_datetime64 SA01" \
197194
-i "pandas.Timestamp.tzinfo GL08" \
198195
-i "pandas.Timestamp.value GL08" \
199196
-i "pandas.Timestamp.year GL08" \

pandas/_libs/tslibs/nattype.pyx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,17 @@ cdef class _NaT(datetime):
229229

230230
def to_datetime64(self) -> np.datetime64:
231231
"""
232-
Return a numpy.datetime64 object with same precision.
232+
Return a NumPy datetime64 object with same precision.
233+
234+
This method returns a numpy.datetime64 object with the same
235+
date and time information and precision as the pd.Timestamp object.
236+
237+
See Also
238+
--------
239+
numpy.datetime64 : Class to represent dates and times with high precision.
240+
Timestamp.to_numpy : Alias for this method.
241+
Timestamp.asm8 : Alias for this method.
242+
pd.to_datetime : Convert argument to datetime.
233243

234244
Examples
235245
--------
@@ -764,6 +774,19 @@ class NaTType(_NaT):
764774
"""
765775
Return time object with same time and tzinfo.
766776
777+
This method returns a datetime.time object with
778+
the time and tzinfo corresponding to the pd.Timestamp
779+
object, ignoring any information about the day/date.
780+
781+
See Also
782+
--------
783+
datetime.datetime.timetz : Return datetime.time object with the
784+
same time attributes as the datetime object.
785+
datetime.time : Class to represent the time of day, independent
786+
of any particular day.
787+
datetime.datetime.tzinfo : Attribute of datetime.datetime objects
788+
representing the timezone of the datetime object.
789+
767790
Examples
768791
--------
769792
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
@@ -860,9 +883,27 @@ class NaTType(_NaT):
860883
strptime = _make_error_func(
861884
"strptime",
862885
"""
863-
Timestamp.strptime(string, format)
886+
Convert string argument to datetime.
864887
865-
Function is not implemented. Use pd.to_datetime().
888+
This method is not implemented; calling it will raise NotImplementedError.
889+
Use pd.to_datetime() instead.
890+
891+
Parameters
892+
----------
893+
date_string : str
894+
String to convert to a datetime.
895+
format : str, default None
896+
The format string to parse time, e.g. "%d/%m/%Y".
897+
898+
See Also
899+
--------
900+
pd.to_datetime : Convert argument to datetime.
901+
datetime.datetime.strptime : Return a datetime corresponding to a string
902+
representing a date and time, parsed according to a separate
903+
format string.
904+
datetime.datetime.strftime : Return a string representing the date and
905+
time, controlled by an explicit format string.
906+
Timestamp.isoformat : Return the time formatted according to ISO 8601.
866907
867908
Examples
868909
--------

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,17 @@ cdef class _Timestamp(ABCTimestamp):
13421342
13431343
cpdef to_datetime64(self):
13441344
"""
1345-
Return a numpy.datetime64 object with same precision.
1345+
Return a NumPy datetime64 object with same precision.
1346+
1347+
This method returns a numpy.datetime64 object with the same
1348+
date and time information and precision as the pd.Timestamp object.
1349+
1350+
See Also
1351+
--------
1352+
numpy.datetime64 : Class to represent dates and times with high precision.
1353+
Timestamp.to_numpy : Alias for this method.
1354+
Timestamp.asm8 : Alias for this method.
1355+
pd.to_datetime : Convert argument to datetime.
13461356

13471357
Examples
13481358
--------
@@ -2093,6 +2103,19 @@ class Timestamp(_Timestamp):
20932103
"""
20942104
Return time object with same time and tzinfo.
20952105

2106+
This method returns a datetime.time object with
2107+
the time and tzinfo corresponding to the pd.Timestamp
2108+
object, ignoring any information about the day/date.
2109+
2110+
See Also
2111+
--------
2112+
datetime.datetime.timetz : Return datetime.time object with the
2113+
same time attributes as the datetime object.
2114+
datetime.time : Class to represent the time of day, independent
2115+
of any particular day.
2116+
datetime.datetime.tzinfo : Attribute of datetime.datetime objects
2117+
representing the timezone of the datetime object.
2118+
20962119
Examples
20972120
--------
20982121
>>> ts = pd.Timestamp('2023-01-01 10:00:00', tz='Europe/Brussels')
@@ -2141,9 +2164,27 @@ class Timestamp(_Timestamp):
21412164
@classmethod
21422165
def strptime(cls, date_string, format):
21432166
"""
2144-
Timestamp.strptime(string, format)
2167+
Convert string argument to datetime.
21452168

2146-
Function is not implemented. Use pd.to_datetime().
2169+
This method is not implemented; calling it will raise NotImplementedError.
2170+
Use pd.to_datetime() instead.
2171+
2172+
Parameters
2173+
----------
2174+
date_string : str
2175+
String to convert to a datetime.
2176+
format : str, default None
2177+
The format string to parse time, e.g. "%d/%m/%Y".
2178+
2179+
See Also
2180+
--------
2181+
pd.to_datetime : Convert argument to datetime.
2182+
datetime.datetime.strptime : Return a datetime corresponding to a string
2183+
representing a date and time, parsed according to a separate
2184+
format string.
2185+
datetime.datetime.strftime : Return a string representing the date and
2186+
time, controlled by an explicit format string.
2187+
Timestamp.isoformat : Return the time formatted according to ISO 8601.
21472188

21482189
Examples
21492190
--------
@@ -3073,7 +3114,8 @@ default 'raise'
30733114
"""
30743115
Convert TimeStamp to a Julian Date.
30753116

3076-
0 Julian date is noon January 1, 4713 BC.
3117+
This method returns the number of days as a float since
3118+
0 Julian date, which is noon January 1, 4713 BC.
30773119

30783120
See Also
30793121
--------

0 commit comments

Comments
 (0)