Skip to content

Commit 66884fd

Browse files
DOC: Added docstrings to min/max/reso for Timedelta (#61119)
* Added docstrings to min/max/reso for Timedelta * Converted new Timedelta attributes to private --------- Co-authored-by: John Hendricks <[email protected]>
1 parent 1e899af commit 66884fd

File tree

2 files changed

+77
-9
lines changed

2 files changed

+77
-9
lines changed

ci/code_checks.sh

-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
7272
-i "pandas.Series.dt PR01" `# Accessors are implemented as classes, but we do not document the Parameters section` \
7373
-i "pandas.Period.freq GL08" \
7474
-i "pandas.Period.ordinal GL08" \
75-
-i "pandas.Timedelta.max PR02" \
76-
-i "pandas.Timedelta.min PR02" \
77-
-i "pandas.Timedelta.resolution PR02" \
7875
-i "pandas.Timestamp.max PR02" \
7976
-i "pandas.Timestamp.min PR02" \
8077
-i "pandas.Timestamp.resolution PR02" \

pandas/_libs/tslibs/timedeltas.pyx

+77-6
Original file line numberDiff line numberDiff line change
@@ -998,8 +998,9 @@ class MinMaxReso:
998998
and Timedelta class. On an instance, these depend on the object's _reso.
999999
On the class, we default to the values we would get with nanosecond _reso.
10001000
"""
1001-
def __init__(self, name):
1001+
def __init__(self, name, docstring):
10021002
self._name = name
1003+
self.__doc__ = docstring
10031004

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

10131014
if obj is None:
10141015
# i.e. this is on the class, default to nanos
1015-
return Timedelta(val)
1016+
result = Timedelta(val)
10161017
else:
1017-
return Timedelta._from_value_and_reso(val, obj._creso)
1018+
result = Timedelta._from_value_and_reso(val, obj._creso)
1019+
1020+
result.__doc__ = self.__doc__
1021+
1022+
return result
10181023

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

10341039
# higher than np.ndarray and np.matrix
10351040
__array_priority__ = 100
1036-
min = MinMaxReso("min")
1037-
max = MinMaxReso("max")
1038-
resolution = MinMaxReso("resolution")
1041+
1042+
_docstring_min = """
1043+
Returns the minimum bound possible for Timedelta.
1044+
1045+
This property provides access to the smallest possible value that
1046+
can be represented by a Timedelta object.
1047+
1048+
Returns
1049+
-------
1050+
Timedelta
1051+
1052+
See Also
1053+
--------
1054+
Timedelta.max: Returns the maximum bound possible for Timedelta.
1055+
Timedelta.resolution: Returns the smallest possible difference between
1056+
non-equal Timedelta objects.
1057+
1058+
Examples
1059+
--------
1060+
>>> pd.Timedelta.min
1061+
-106752 days +00:12:43.145224193
1062+
"""
1063+
1064+
_docstring_max = """
1065+
Returns the maximum bound possible for Timedelta.
1066+
1067+
This property provides access to the largest possible value that
1068+
can be represented by a Timedelta object.
1069+
1070+
Returns
1071+
-------
1072+
Timedelta
1073+
1074+
See Also
1075+
--------
1076+
Timedelta.min: Returns the minimum bound possible for Timedelta.
1077+
Timedelta.resolution: Returns the smallest possible difference between
1078+
non-equal Timedelta objects.
1079+
1080+
Examples
1081+
--------
1082+
>>> pd.Timedelta.max
1083+
106751 days 23:47:16.854775807
1084+
"""
1085+
1086+
_docstring_reso = """
1087+
Returns the smallest possible difference between non-equal Timedelta objects.
1088+
1089+
The resolution value is determined by the underlying representation of time
1090+
units and is equivalent to Timedelta(nanoseconds=1).
1091+
1092+
Returns
1093+
-------
1094+
Timedelta
1095+
1096+
See Also
1097+
--------
1098+
Timedelta.max: Returns the maximum bound possible for Timedelta.
1099+
Timedelta.min: Returns the minimum bound possible for Timedelta.
1100+
1101+
Examples
1102+
--------
1103+
>>> pd.Timedelta.resolution
1104+
0 days 00:00:00.000000001
1105+
"""
1106+
1107+
min = MinMaxReso("min", _docstring_min)
1108+
max = MinMaxReso("max", _docstring_max)
1109+
resolution = MinMaxReso("resolution", _docstring_reso)
10391110

10401111
@property
10411112
def value(self):

0 commit comments

Comments
 (0)