Skip to content

DOC: Added docstrings to min/max/reso for Timedelta #61119

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

Merged
merged 3 commits into from
Mar 17, 2025
Merged
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
3 changes: 0 additions & 3 deletions ci/code_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
-i "pandas.Period.freq GL08" \
-i "pandas.Period.ordinal GL08" \
-i "pandas.Timedelta.max PR02" \
-i "pandas.Timedelta.min PR02" \
-i "pandas.Timedelta.resolution PR02" \
-i "pandas.Timestamp.max PR02" \
-i "pandas.Timestamp.min PR02" \
-i "pandas.Timestamp.resolution PR02" \
Expand Down
83 changes: 77 additions & 6 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -998,8 +998,9 @@ class MinMaxReso:
and Timedelta class. On an instance, these depend on the object's _reso.
On the class, we default to the values we would get with nanosecond _reso.
"""
def __init__(self, name):
def __init__(self, name, docstring):
self._name = name
self.__doc__ = docstring

def __get__(self, obj, type=None):
if self._name == "min":
Expand All @@ -1012,9 +1013,13 @@ class MinMaxReso:

if obj is None:
# i.e. this is on the class, default to nanos
return Timedelta(val)
result = Timedelta(val)
else:
return Timedelta._from_value_and_reso(val, obj._creso)
result = Timedelta._from_value_and_reso(val, obj._creso)

result.__doc__ = self.__doc__

return result

def __set__(self, obj, value):
raise AttributeError(f"{self._name} is not settable.")
Expand All @@ -1033,9 +1038,75 @@ cdef class _Timedelta(timedelta):

# higher than np.ndarray and np.matrix
__array_priority__ = 100
min = MinMaxReso("min")
max = MinMaxReso("max")
resolution = MinMaxReso("resolution")

_docstring_min = """
Returns the minimum bound possible for Timedelta.

This property provides access to the smallest possible value that
can be represented by a Timedelta object.

Returns
-------
Timedelta

See Also
--------
Timedelta.max: Returns the maximum bound possible for Timedelta.
Timedelta.resolution: Returns the smallest possible difference between
non-equal Timedelta objects.

Examples
--------
>>> pd.Timedelta.min
-106752 days +00:12:43.145224193
"""

_docstring_max = """
Returns the maximum bound possible for Timedelta.

This property provides access to the largest possible value that
can be represented by a Timedelta object.

Returns
-------
Timedelta

See Also
--------
Timedelta.min: Returns the minimum bound possible for Timedelta.
Timedelta.resolution: Returns the smallest possible difference between
non-equal Timedelta objects.

Examples
--------
>>> pd.Timedelta.max
106751 days 23:47:16.854775807
"""

_docstring_reso = """
Returns the smallest possible difference between non-equal Timedelta objects.

The resolution value is determined by the underlying representation of time
units and is equivalent to Timedelta(nanoseconds=1).

Returns
-------
Timedelta

See Also
--------
Timedelta.max: Returns the maximum bound possible for Timedelta.
Timedelta.min: Returns the minimum bound possible for Timedelta.

Examples
--------
>>> pd.Timedelta.resolution
0 days 00:00:00.000000001
"""

min = MinMaxReso("min", _docstring_min)
max = MinMaxReso("max", _docstring_max)
resolution = MinMaxReso("resolution", _docstring_reso)

@property
def value(self):
Expand Down