@@ -244,16 +244,24 @@ cdef class _NaT(datetime):
244
244
245
245
def to_numpy(self , dtype = None , copy = False ) -> np.datetime64 | np.timedelta64:
246
246
"""
247
- Convert the Timestamp to a NumPy datetime64 or timedelta64 .
247
+ Convert the Timestamp to a NumPy datetime64.
248
248
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
252
251
will not affect the return value.
253
252
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
+
254
262
Returns
255
263
-------
256
- numpy.datetime64 or numpy. timedelta64
264
+ numpy.datetime64
257
265
258
266
See Also
259
267
--------
@@ -269,9 +277,6 @@ cdef class _NaT(datetime):
269
277
270
278
>>> pd.NaT.to_numpy()
271
279
numpy.datetime64('NaT')
272
-
273
- >>> pd.NaT.to_numpy("m8[ns]")
274
- numpy.timedelta64('NaT','ns')
275
280
"""
276
281
if dtype is not None:
277
282
# GH#44460
@@ -476,6 +481,11 @@ class NaTType(_NaT):
476
481
"""
477
482
Return the month name of the Timestamp with specified locale.
478
483
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
+
479
489
Parameters
480
490
----------
481
491
locale : str, default None (English locale)
@@ -484,9 +494,18 @@ class NaTType(_NaT):
484
494
Returns
485
495
-------
486
496
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.
487
504
488
505
Examples
489
506
--------
507
+ Get the month name in English (default):
508
+
490
509
>>> ts = pd.Timestamp('2020-03-14T15:32:52.192548651')
491
510
>>> ts.month_name()
492
511
'March'
@@ -581,10 +600,25 @@ class NaTType(_NaT):
581
600
date = _make_nat_func(
582
601
" date" ,
583
602
"""
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.
585
617
586
618
Examples
587
619
--------
620
+ Extract the date from a Timestamp:
621
+
588
622
>>> ts = pd.Timestamp('2023-01-01 10:00:00.00')
589
623
>>> ts
590
624
Timestamp('2023-01-01 10:00:00')
@@ -704,6 +738,17 @@ class NaTType(_NaT):
704
738
"""
705
739
Return time tuple, compatible with time.localtime().
706
740
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
+
707
752
Examples
708
753
--------
709
754
>>> ts = pd.Timestamp('2023-01-01 10:00:00')
@@ -733,6 +778,17 @@ class NaTType(_NaT):
733
778
"""
734
779
Return proleptic Gregorian ordinal. January 1 of year 1 is day 1.
735
780
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
+
736
792
Examples
737
793
--------
738
794
>>> ts = pd.Timestamp('2023-01-01 10:00:50')
@@ -745,7 +801,25 @@ class NaTType(_NaT):
745
801
ctime = _make_error_func(
746
802
" ctime" ,
747
803
"""
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.
749
823
750
824
Examples
751
825
--------
@@ -834,24 +908,72 @@ class NaTType(_NaT):
834
908
fromtimestamp = _make_error_func(
835
909
" fromtimestamp" ,
836
910
"""
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.
838
930
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.
840
936
841
937
Examples
842
938
--------
939
+ Convert a POSIX timestamp to a `Timestamp`:
940
+
843
941
>>> pd.Timestamp.fromtimestamp(1584199972) # doctest: +SKIP
844
942
Timestamp('2020-03-14 15:32:52')
845
943
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')
847
948
""" ,
848
949
)
849
950
combine = _make_error_func(
850
951
" combine" ,
851
952
"""
852
953
Timestamp.combine(date, time)
853
954
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.
855
977
856
978
Examples
857
979
--------
@@ -962,21 +1084,43 @@ class NaTType(_NaT):
962
1084
"""
963
1085
Construct a timestamp from a a proleptic Gregorian ordinal.
964
1086
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
+
965
1092
Parameters
966
1093
----------
967
1094
ordinal : int
968
1095
Date corresponding to a proleptic Gregorian ordinal.
969
1096
tz : str, zoneinfo.ZoneInfo, pytz.timezone, dateutil.tz.tzfile or None
970
1097
Time zone for the Timestamp.
971
1098
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
+
972
1109
Notes
973
1110
-----
974
1111
By definition there cannot be any tz info on the ordinal itself.
975
1112
976
1113
Examples
977
1114
--------
1115
+ Convert an ordinal to a `Timestamp`:
1116
+
978
1117
>>> pd.Timestamp.fromordinal(737425)
979
1118
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')
980
1124
""" ,
981
1125
)
982
1126
@@ -1068,6 +1212,12 @@ class NaTType(_NaT):
1068
1212
tz : str or timezone object, default None
1069
1213
Timezone to localize to.
1070
1214
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
+
1071
1221
Examples
1072
1222
--------
1073
1223
>>> pd.Timestamp.today() # doctest: +SKIP
@@ -1518,22 +1668,48 @@ default 'raise'
1518
1668
"""
1519
1669
Implements datetime.replace, handles nanoseconds.
1520
1670
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
+
1521
1676
Parameters
1522
1677
----------
1523
1678
year : int, optional
1679
+ The year to replace. If `None`, the year is not changed.
1524
1680
month : int, optional
1681
+ The month to replace. If `None`, the month is not changed.
1525
1682
day : int, optional
1683
+ The day to replace. If `None`, the day is not changed.
1526
1684
hour : int, optional
1685
+ The hour to replace. If `None`, the hour is not changed.
1527
1686
minute : int, optional
1687
+ The minute to replace. If `None`, the minute is not changed.
1528
1688
second : int, optional
1689
+ The second to replace. If `None`, the second is not changed.
1529
1690
microsecond : int, optional
1691
+ The microsecond to replace. If `None`, the microsecond is not changed.
1530
1692
nanosecond : int, optional
1693
+ The nanosecond to replace. If `None`, the nanosecond is not changed.
1531
1694
tzinfo : tz-convertible, optional
1695
+ The timezone information to replace. If `None`, the timezone is not changed.
1532
1696
fold : int, optional
1697
+ The fold information to replace. If `None`, the fold is not changed.
1533
1698
1534
1699
Returns
1535
1700
-------
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.
1537
1713
1538
1714
Examples
1539
1715
--------
0 commit comments