Skip to content

Commit d703210

Browse files
Fix docstrings for Timestamp: normalize, replace, to_numpy, to_period
1 parent 0cdc6a4 commit d703210

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

ci/code_checks.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
218218
-i "pandas.Timestamp.month GL08" \
219219
-i "pandas.Timestamp.month_name SA01" \
220220
-i "pandas.Timestamp.nanosecond GL08" \
221-
-i "pandas.Timestamp.normalize SA01" \
222221
-i "pandas.Timestamp.quarter SA01" \
223-
-i "pandas.Timestamp.replace PR07,SA01" \
224222
-i "pandas.Timestamp.resolution PR02" \
225223
-i "pandas.Timestamp.second GL08" \
226224
-i "pandas.Timestamp.strptime PR01,SA01" \
@@ -229,8 +227,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
229227
-i "pandas.Timestamp.timetz SA01" \
230228
-i "pandas.Timestamp.to_datetime64 SA01" \
231229
-i "pandas.Timestamp.to_julian_date SA01" \
232-
-i "pandas.Timestamp.to_numpy PR01" \
233-
-i "pandas.Timestamp.to_period PR01,SA01" \
234230
-i "pandas.Timestamp.today SA01" \
235231
-i "pandas.Timestamp.toordinal SA01" \
236232
-i "pandas.Timestamp.tz_localize SA01" \

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,13 @@ cdef class _Timestamp(ABCTimestamp):
953953

954954
def normalize(self) -> "Timestamp":
955955
"""
956-
Normalize Timestamp to midnight, preserving tz information.
956+
Normalize Timestamp to previous midnight, preserving tz information.
957+
958+
This is equivalent to replacing the time part of the timestamp with `00:00:00`.
959+
960+
See Also
961+
--------
962+
Timestamp.replace : Return a new timestamp with replaced attributes.
957963

958964
Examples
959965
--------
@@ -1276,6 +1282,13 @@ cdef class _Timestamp(ABCTimestamp):
12761282
copy parameters are available here only for compatibility. Their values
12771283
will not affect the return value.
12781284

1285+
Parameters
1286+
----------
1287+
dtype : numpy.dtype, default None
1288+
Must be None. Otherwise, a ValueError is raised.
1289+
copy : bool, default False
1290+
Must be False. Otherwise, a ValueError is raised.
1291+
12791292
Returns
12801293
-------
12811294
numpy.datetime64
@@ -1303,7 +1316,20 @@ cdef class _Timestamp(ABCTimestamp):
13031316

13041317
def to_period(self, freq=None):
13051318
"""
1306-
Return an period of which this timestamp is an observation.
1319+
Return a period of which this timestamp is an observation.
1320+
1321+
This method constructs a `Period` object from the `Timestamp` and provided period.
1322+
Please note that timezone information will be dropped, since `Period` doesn't support timezones.
1323+
1324+
Parameters
1325+
----------
1326+
freq : str, default None
1327+
The period frequency. Accepted strings are listed in the :ref:`period alias section <timeseries.period_aliases>` in the user docs.
1328+
1329+
See Also
1330+
--------
1331+
Period : Represents a period of time.
1332+
Period.to_timestamp : Return the Timestamp representation of the Period.
13071333
13081334
Examples
13091335
--------
@@ -2603,23 +2629,42 @@ default 'raise'
26032629
"""
26042630
Implements datetime.replace, handles nanoseconds.
26052631
2632+
Returns a new timestamp with the same attributes, except for those given new value.
2633+
26062634
Parameters
26072635
----------
26082636
year : int, optional
2637+
New year value.
26092638
month : int, optional
2639+
New month value.
26102640
day : int, optional
2641+
New day value.
26112642
hour : int, optional
2643+
New hour value.
26122644
minute : int, optional
2645+
New minute value.
26132646
second : int, optional
2647+
New second value.
26142648
microsecond : int, optional
2649+
New microsecond value.
26152650
nanosecond : int, optional
2651+
New nanosecond value.
26162652
tzinfo : tz-convertible, optional
2653+
New tzinfo value.
26172654
fold : int, optional
2655+
New fold value.
26182656
26192657
Returns
26202658
-------
26212659
Timestamp with fields replaced
26222660
2661+
See Also
2662+
--------
2663+
Timestamp.normalize : Normalize the Timestamp to midnight, preserving tz information.
2664+
Timestamp.tz_convert : Convert timezone-aware Timestamp to another time zone.
2665+
Timestamp.tz_localize : Localize the Timestamp to a timezone.
2666+
datetime.datetime.replace : Return a new datetime with replaced attributes.
2667+
26232668
Examples
26242669
--------
26252670
Create a timestamp object:

0 commit comments

Comments
 (0)