diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 8f4e719ad7cd6..3d9cab04c4cee 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -301,7 +301,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then -i "pandas.Timestamp.to_julian_date SA01" \ -i "pandas.Timestamp.to_numpy PR01" \ -i "pandas.Timestamp.to_period PR01,SA01" \ - -i "pandas.Timestamp.to_pydatetime PR01,SA01" \ -i "pandas.Timestamp.today SA01" \ -i "pandas.Timestamp.toordinal SA01" \ -i "pandas.Timestamp.tz SA01" \ diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index cf7c20d84c2d4..2cf97c9213f68 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -882,7 +882,30 @@ class NaTType(_NaT): """ Convert a Timestamp object to a native Python datetime object. - If warn=True, issue a warning if nanoseconds is nonzero. + This method is useful for when you need to utilize a pandas Timestamp + object in contexts where native Python datetime objects are expected + or required. The conversion discards the nanoseconds component, and a + warning can be issued in such cases if desired. + + Parameters + ---------- + warn : bool, default True + If True, issues a warning when the timestamp includes nonzero + nanoseconds, as these will be discarded during the conversion. + + Returns + ------- + datetime.datetime or NaT + Returns a datetime.datetime object representing the timestamp, + with year, month, day, hour, minute, second, and microsecond components. + If the timestamp is NaT (Not a Time), returns NaT. + + See Also + -------- + datetime.datetime : The standard Python datetime class that this method + returns. + Timestamp.timestamp : Convert a Timestamp object to POSIX timestamp. + Timestamp.to_datetime64 : Convert a Timestamp object to numpy.datetime64. Examples -------- diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index bcd758b9a9042..096642c7034eb 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1196,7 +1196,30 @@ cdef class _Timestamp(ABCTimestamp): """ Convert a Timestamp object to a native Python datetime object. - If warn=True, issue a warning if nanoseconds is nonzero. + This method is useful for when you need to utilize a pandas Timestamp + object in contexts where native Python datetime objects are expected + or required. The conversion discards the nanoseconds component, and a + warning can be issued in such cases if desired. + + Parameters + ---------- + warn : bool, default True + If True, issues a warning when the timestamp includes nonzero + nanoseconds, as these will be discarded during the conversion. + + Returns + ------- + datetime.datetime or NaT + Returns a datetime.datetime object representing the timestamp, + with year, month, day, hour, minute, second, and microsecond components. + If the timestamp is NaT (Not a Time), returns NaT. + + See Also + -------- + datetime.datetime : The standard Python datetime class that this method + returns. + Timestamp.timestamp : Convert a Timestamp object to POSIX timestamp. + Timestamp.to_datetime64 : Convert a Timestamp object to numpy.datetime64. Examples --------