From bab714d1cce14058295b454a62fb6eacaa95cab4 Mon Sep 17 00:00:00 2001 From: tuhinsharma121 Date: Mon, 13 May 2024 18:08:19 +0530 Subject: [PATCH 1/4] DOC: add SA01,ES01 for pandas.Timestamp.to_pydatetime --- pandas/_libs/tslibs/timestamps.pyx | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index bcd758b9a9042..e4429f3a6060c 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1196,7 +1196,29 @@ 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 -------- From fd6702b87f271e1c5fe336792771db47e8de2efb Mon Sep 17 00:00:00 2001 From: tuhinsharma121 Date: Mon, 13 May 2024 18:10:02 +0530 Subject: [PATCH 2/4] DOC: add SA01,ES01 for pandas.Timestamp.to_pydatetime --- pandas/_libs/tslibs/timestamps.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index e4429f3a6060c..096642c7034eb 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -1216,7 +1216,8 @@ cdef class _Timestamp(ABCTimestamp): See Also -------- - datetime.datetime : The standard Python datetime class that this method returns. + 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. From 3a55c5fddd40ec658dbea9aac2bb702f9e84dea2 Mon Sep 17 00:00:00 2001 From: tuhinsharma121 Date: Mon, 13 May 2024 18:10:40 +0530 Subject: [PATCH 3/4] DOC: remove SA01,ES01 for pandas.Timestamp.to_pydatetime --- ci/code_checks.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 24321f8ef54f7..5df0c02d59d60 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -303,7 +303,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" \ From 752b36ba4ca6b0af1f2d4edf3094fa7046c7c785 Mon Sep 17 00:00:00 2001 From: tuhinsharma121 Date: Tue, 14 May 2024 11:24:08 +0530 Subject: [PATCH 4/4] DOC: change docstring in sync with pandas.Timestamp.to_pydatetime --- pandas/_libs/tslibs/nattype.pyx | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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 --------