Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc errors for various datetime functions #59791

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.dt.month_name PR01,PR02" \
-i "pandas.Series.dt.normalize PR01" \
-i "pandas.Series.dt.round PR01,PR02" \
-i "pandas.Series.dt.strftime PR01,PR02" \
-i "pandas.Series.dt.to_period PR01,PR02" \
-i "pandas.Series.dt.total_seconds PR01" \
-i "pandas.Series.dt.tz_convert PR01,PR02" \
-i "pandas.Series.dt.tz_localize PR01,PR02" \
-i "pandas.Series.dt.unit GL08" \
-i "pandas.Series.dt.strftime PR02" \
-i "pandas.Series.dt.to_period PR02" \
-i "pandas.Series.dt.tz_convert PR02" \
-i "pandas.Series.dt.tz_localize PR02" \
-i "pandas.Series.pad PR01,SA01" \
-i "pandas.Series.sparse.fill_value SA01" \
-i "pandas.Series.sparse.from_coo PR07,SA01" \
Expand Down
24 changes: 24 additions & 0 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,12 @@ def strftime(self, date_format: str) -> npt.NDArray[np.object_]:
----------
date_format : str
Date format string (e.g. "%%Y-%%m-%%d").
*args
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.
**kwargs
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.

Returns
-------
Expand Down Expand Up @@ -2060,6 +2066,24 @@ def _creso(self) -> int:

@cache_readonly
def unit(self) -> str:
"""
The precision of the datetime data.

Returns the most precise unit used for the datetime data.

See Also
--------
TimelikeOps.as_unit : Converts to a specific unit.

Examples
--------
>>> idx = pd.DatetimeIndex(["2020-01-02 01:02:03.004005006"])
>>> idx.unit
'ns'
>>> idx = pd.DatetimeIndex(["2020-01-02 01:02:03"])
>>> idx.unit
's'
"""
# e.g. "ns", "us", "ms"
# error: Argument 1 to "dtype_to_unit" has incompatible type
# "ExtensionDtype"; expected "Union[DatetimeTZDtype, dtype[Any]]"
Expand Down
23 changes: 23 additions & 0 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,12 +854,23 @@ def tz_convert(self, tz) -> Self:
"""
Convert tz-aware Datetime Array/Index from one time zone to another.

This method is used to convert a timezone-aware Datetime Array or Index to
a different time zone. The original UTC time remains the same; only the
time zone information is changed. If the Timestamp is timezone-naive, a
TypeError is raised.

Parameters
----------
tz : str, zoneinfo.ZoneInfo, pytz.timezone, dateutil.tz.tzfile, datetime.tzinfo or None
Time zone for time. Corresponding timestamps would be converted
to this time zone of the Datetime Array/Index. A `tz` of None will
convert to UTC and remove the timezone information.
*args
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.
**kwargs
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.

Returns
-------
Expand Down Expand Up @@ -981,6 +992,12 @@ def tz_localize(
- timedelta objects will shift nonexistent times by the timedelta
- 'raise' will raise a ValueError if there are
nonexistent times.
*args
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.
**kwargs
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.

Returns
-------
Expand Down Expand Up @@ -1200,6 +1217,12 @@ def to_period(self, freq=None) -> PeriodArray:
freq : str or Period, optional
One of pandas' :ref:`period aliases <timeseries.period_aliases>`
or an Period object. Will be inferred by default.
*args
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.
**kwargs
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.

Returns
-------
Expand Down
9 changes: 9 additions & 0 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,15 @@ def total_seconds(self) -> npt.NDArray[np.float64]:
This method is available directly on TimedeltaArray, TimedeltaIndex
and on Series containing timedelta values under the ``.dt`` namespace.

Parameters
----------
*args
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.
**kwargs
Additional arguments and keywords have no effect but might be
accepted for compatibility with NumPy.

Returns
-------
ndarray, Index or Series
Expand Down
Loading