Skip to content

Commit

Permalink
DOC: Fix SA01 ES01 for pandas.Timestamp.to_pydatetime (#58701)
Browse files Browse the repository at this point in the history
* DOC: add SA01,ES01 for pandas.Timestamp.to_pydatetime

* DOC: add SA01,ES01 for pandas.Timestamp.to_pydatetime

* DOC: remove SA01,ES01 for pandas.Timestamp.to_pydatetime

* DOC: change docstring in sync with pandas.Timestamp.to_pydatetime
  • Loading branch information
tuhinsharma121 committed May 14, 2024
1 parent 7d3474a commit e9a2e66
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
1 change: 0 additions & 1 deletion ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
25 changes: 24 additions & 1 deletion pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down
25 changes: 24 additions & 1 deletion pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down

0 comments on commit e9a2e66

Please sign in to comment.