Skip to content

Commit a72c94c

Browse files
committed
fix Docstring validation err
1 parent 1cfb522 commit a72c94c

File tree

1 file changed

+191
-15
lines changed

1 file changed

+191
-15
lines changed

pandas/_libs/tslibs/nattype.pyx

Lines changed: 191 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,24 @@ cdef class _NaT(datetime):
244244

245245
def to_numpy(self, dtype=None, copy=False) -> np.datetime64 | np.timedelta64:
246246
"""
247-
Convert the Timestamp to a NumPy datetime64 or timedelta64.
247+
Convert the Timestamp to a NumPy datetime64.
248248

249-
With the default 'dtype', this is an alias method for `NaT.to_datetime64()`.
250-
251-
The copy parameter is available here only for compatibility. Its value
249+
This is an alias method for `Timestamp.to_datetime64()`. The dtype and
250+
copy parameters are available here only for compatibility. Their values
252251
will not affect the return value.
253252

253+
Parameters
254+
----------
255+
dtype : dtype, optional
256+
Data type of the output, ignored in this method as the return type
257+
is always `numpy.datetime64`.
258+
copy : bool, default False
259+
Whether to ensure that the returned value is a new object. This
260+
parameter is also ignored as the method does not support copying.
261+
254262
Returns
255263
-------
256-
numpy.datetime64 or numpy.timedelta64
264+
numpy.datetime64
257265

258266
See Also
259267
--------
@@ -269,9 +277,6 @@ cdef class _NaT(datetime):
269277

270278
>>> pd.NaT.to_numpy()
271279
numpy.datetime64('NaT')
272-
273-
>>> pd.NaT.to_numpy("m8[ns]")
274-
numpy.timedelta64('NaT','ns')
275280
"""
276281
if dtype is not None:
277282
# GH#44460
@@ -476,6 +481,11 @@ class NaTType(_NaT):
476481
"""
477482
Return the month name of the Timestamp with specified locale.
478483
484+
This method returns the full name of the month corresponding to the
485+
`Timestamp`, such as 'January', 'February', etc. The month name can
486+
be returned in a specified locale if provided; otherwise, it defaults
487+
to the English locale.
488+
479489
Parameters
480490
----------
481491
locale : str, default None (English locale)
@@ -484,9 +494,18 @@ class NaTType(_NaT):
484494
Returns
485495
-------
486496
str
497+
The full month name as a string.
498+
499+
See Also
500+
--------
501+
Timestamp.day_name : Returns the name of the day of the week.
502+
Timestamp.strftime : Returns a formatted string of the Timestamp.
503+
datetime.datetime.strftime : Returns a string representing the date and time.
487504
488505
Examples
489506
--------
507+
Get the month name in English (default):
508+
490509
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
491510
>>> ts.month_name()
492511
'March'
@@ -581,10 +600,25 @@ class NaTType(_NaT):
581600
date = _make_nat_func(
582601
"date",
583602
"""
584-
Return date object with same year, month and day.
603+
Returns `datetime.date` with the same year, month, and day.
604+
605+
This method extracts the date component from the `Timestamp` and returns
606+
it as a `datetime.date` object, discarding the time information.
607+
608+
Returns
609+
-------
610+
datetime.date
611+
The date part of the `Timestamp`.
612+
613+
See Also
614+
--------
615+
Timestamp : Represents a single timestamp, similar to `datetime`.
616+
datetime.datetime.date : Extract the date component from a `datetime` object.
585617
586618
Examples
587619
--------
620+
Extract the date from a Timestamp:
621+
588622
>>> ts = pd.Timestamp('2023-01-01 10:00:00.00')
589623
>>> ts
590624
Timestamp('2023-01-01 10:00:00')
@@ -704,6 +738,17 @@ class NaTType(_NaT):
704738
"""
705739
Return time tuple, compatible with time.localtime().
706740
741+
This method converts the `Timestamp` into a time tuple, which is compatible
742+
with functions like `time.localtime()`. The time tuple is a named tuple with
743+
attributes such as year, month, day, hour, minute, second, weekday,
744+
day of the year, and daylight savings indicator.
745+
746+
See Also
747+
--------
748+
time.localtime : Converts a POSIX timestamp into a time tuple.
749+
Timestamp : The `Timestamp` that represents a specific point in time.
750+
datetime.datetime.timetuple : Equivalent method in the `datetime` module.
751+
707752
Examples
708753
--------
709754
>>> ts = pd.Timestamp('2023-01-01 10:00:00')
@@ -733,6 +778,17 @@ class NaTType(_NaT):
733778
"""
734779
Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.
735780
781+
The proleptic Gregorian ordinal is a continuous count of days since
782+
January 1 of year 1, which is considered day 1. This method converts
783+
the `Timestamp` to its equivalent ordinal number, useful for date arithmetic
784+
and comparison operations.
785+
786+
See Also
787+
--------
788+
datetime.datetime.toordinal : Equivalent method in the `datetime` module.
789+
Timestamp : The `Timestamp` that represents a specific point in time.
790+
Timestamp.fromordinal : Create a `Timestamp` from an ordinal.
791+
736792
Examples
737793
--------
738794
>>> ts = pd.Timestamp('2023-01-01 10:00:50')
@@ -745,7 +801,25 @@ class NaTType(_NaT):
745801
ctime = _make_error_func(
746802
"ctime",
747803
"""
748-
Return ctime() style string.
804+
Return a ctime() style string representing the Timestamp.
805+
806+
This method returns a string representing the date and time
807+
in the format returned by the standard library's `time.ctime()`
808+
function, which is typically in the form 'Day Mon DD HH:MM:SS YYYY'.
809+
810+
If the `Timestamp` is outside the range supported by Python's
811+
standard library, a `NotImplementedError` is raised.
812+
813+
Returns
814+
-------
815+
str
816+
A string representing the Timestamp in ctime format.
817+
818+
See Also
819+
--------
820+
time.ctime : Return a string representing time in ctime format.
821+
Timestamp : Represents a single timestamp, similar to `datetime`.
822+
datetime.datetime.ctime : Return a ctime style string from a datetime object.
749823
750824
Examples
751825
--------
@@ -834,24 +908,72 @@ class NaTType(_NaT):
834908
fromtimestamp = _make_error_func(
835909
"fromtimestamp",
836910
"""
837-
Timestamp.fromtimestamp(ts)
911+
Create a `Timestamp` object from a POSIX timestamp.
912+
913+
This method converts a POSIX timestamp (the number of seconds since
914+
January 1, 1970, 00:00:00 UTC) into a `Timestamp` object. The resulting
915+
`Timestamp` can be localized to a specific time zone if provided.
916+
917+
Parameters
918+
----------
919+
ts : float
920+
The POSIX timestamp to convert, representing seconds since
921+
the epoch (1970-01-01 00:00:00 UTC).
922+
tz : str, zoneinfo.ZoneInfo, pytz.timezone, dateutil.tz.tzfile, optional
923+
Time zone for the `Timestamp`. If not provided, the `Timestamp` will
924+
be timezone-naive (i.e., without time zone information).
925+
926+
Returns
927+
-------
928+
Timestamp
929+
A `Timestamp` object representing the given POSIX timestamp.
838930
839-
Transform timestamp[, tz] to tz's local time from POSIX timestamp.
931+
See Also
932+
--------
933+
Timestamp : Represents a single timestamp, similar to `datetime`.
934+
to_datetime : Converts various types of data to datetime.
935+
datetime.datetime.fromtimestamp : Returns a datetime from a POSIX timestamp.
840936
841937
Examples
842938
--------
939+
Convert a POSIX timestamp to a `Timestamp`:
940+
843941
>>> pd.Timestamp.fromtimestamp(1584199972) # doctest: +SKIP
844942
Timestamp('2020-03-14 15:32:52')
845943
846-
Note that the output may change depending on your local time.
944+
Note that the output may change depending on your local time and time zone:
945+
946+
>>> pd.Timestamp.fromtimestamp(1584199972, tz='UTC') # doctest: +SKIP
947+
Timestamp('2020-03-14 15:32:52+0000', tz='UTC')
847948
""",
848949
)
849950
combine = _make_error_func(
850951
"combine",
851952
"""
852953
Timestamp.combine(date, time)
853954
854-
Combine date, time into datetime with same date and time fields.
955+
Combine a date and time into a single Timestamp object.
956+
957+
This method takes a `date` object and a `time` object
958+
and combines them into a single `Timestamp`
959+
that has the same date and time fields.
960+
961+
Parameters
962+
----------
963+
date : datetime.date
964+
The date part of the Timestamp.
965+
time : datetime.time
966+
The time part of the Timestamp.
967+
968+
Returns
969+
-------
970+
Timestamp
971+
A new `Timestamp` object representing the combined date and time.
972+
973+
See Also
974+
--------
975+
Timestamp : Represents a single timestamp, similar to `datetime`.
976+
to_datetime : Converts various types of data to datetime.
855977
856978
Examples
857979
--------
@@ -962,21 +1084,43 @@ class NaTType(_NaT):
9621084
"""
9631085
Construct a timestamp from a a proleptic Gregorian ordinal.
9641086
1087+
This method creates a `Timestamp` object corresponding to the given
1088+
proleptic Gregorian ordinal, which is a count of days from January 1,
1089+
0001 (using the proleptic Gregorian calendar). The time part of the
1090+
`Timestamp` is set to midnight (00:00:00) by default.
1091+
9651092
Parameters
9661093
----------
9671094
ordinal : int
9681095
Date corresponding to a proleptic Gregorian ordinal.
9691096
tz : str, zoneinfo.ZoneInfo, pytz.timezone, dateutil.tz.tzfile or None
9701097
Time zone for the Timestamp.
9711098
1099+
Returns
1100+
-------
1101+
Timestamp
1102+
A `Timestamp` object representing the specified ordinal date.
1103+
1104+
See Also
1105+
--------
1106+
Timestamp : Represents a single timestamp, similar to `datetime`.
1107+
to_datetime : Converts various types of data to datetime.
1108+
9721109
Notes
9731110
-----
9741111
By definition there cannot be any tz info on the ordinal itself.
9751112
9761113
Examples
9771114
--------
1115+
Convert an ordinal to a `Timestamp`:
1116+
9781117
>>> pd.Timestamp.fromordinal(737425)
9791118
Timestamp('2020-01-01 00:00:00')
1119+
1120+
Create a `Timestamp` from an ordinal with timezone information:
1121+
1122+
>>> pd.Timestamp.fromordinal(737425, tz='UTC')
1123+
Timestamp('2020-01-01 00:00:00+0000', tz='UTC')
9801124
""",
9811125
)
9821126

@@ -1068,6 +1212,12 @@ class NaTType(_NaT):
10681212
tz : str or timezone object, default None
10691213
Timezone to localize to.
10701214
1215+
See Also
1216+
--------
1217+
datetime.datetime.today : Returns the current local date.
1218+
Timestamp.now : Returns current time with optional timezone.
1219+
Timestamp : A class representing a specific timestamp.
1220+
10711221
Examples
10721222
--------
10731223
>>> pd.Timestamp.today() # doctest: +SKIP
@@ -1518,22 +1668,48 @@ default 'raise'
15181668
"""
15191669
Implements datetime.replace, handles nanoseconds.
15201670
1671+
This method creates a new `Timestamp` object by replacing the specified
1672+
fields with new values. The new `Timestamp` retains the original fields
1673+
that are not explicitly replaced. This method handles nanoseconds, and
1674+
the `tzinfo` parameter allows for timezone replacement without conversion.
1675+
15211676
Parameters
15221677
----------
15231678
year : int, optional
1679+
The year to replace. If `None`, the year is not changed.
15241680
month : int, optional
1681+
The month to replace. If `None`, the month is not changed.
15251682
day : int, optional
1683+
The day to replace. If `None`, the day is not changed.
15261684
hour : int, optional
1685+
The hour to replace. If `None`, the hour is not changed.
15271686
minute : int, optional
1687+
The minute to replace. If `None`, the minute is not changed.
15281688
second : int, optional
1689+
The second to replace. If `None`, the second is not changed.
15291690
microsecond : int, optional
1691+
The microsecond to replace. If `None`, the microsecond is not changed.
15301692
nanosecond : int, optional
1693+
The nanosecond to replace. If `None`, the nanosecond is not changed.
15311694
tzinfo : tz-convertible, optional
1695+
The timezone information to replace. If `None`, the timezone is not changed.
15321696
fold : int, optional
1697+
The fold information to replace. If `None`, the fold is not changed.
15331698
15341699
Returns
15351700
-------
1536-
Timestamp with fields replaced
1701+
Timestamp
1702+
A new `Timestamp` object with the specified fields replaced.
1703+
1704+
See Also
1705+
--------
1706+
Timestamp : Represents a single timestamp, similar to `datetime`.
1707+
to_datetime : Converts various types of data to datetime.
1708+
1709+
Notes
1710+
-----
1711+
The `replace` method does not perform timezone conversions. If you need
1712+
to convert the timezone, use the `tz_convert` method instead.
15371713
15381714
Examples
15391715
--------

0 commit comments

Comments
 (0)