Skip to content

DOC: Added docstrings to min, max, and reso #61238

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
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.Timestamp.max PR02" \
-i "pandas.Timestamp.min PR02" \
-i "pandas.Timestamp.resolution PR02" \
-i "pandas.core.groupby.DataFrameGroupBy.plot PR02" \
-i "pandas.core.groupby.SeriesGroupBy.plot PR02" \
-i "pandas.core.resample.Resampler.quantile PR01,PR07" \
Expand Down
84 changes: 77 additions & 7 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ class MinMaxReso:

See also: timedeltas.MinMaxReso
"""
def __init__(self, name):
def __init__(self, name, docstring):
self._name = name
self.__doc__ = docstring

def __get__(self, obj, type=None):
cls = Timestamp
Expand All @@ -216,11 +217,15 @@ class MinMaxReso:

if obj is None:
# i.e. this is on the class, default to nanos
return cls(val)
result = cls(val)
elif self._name == "resolution":
return Timedelta._from_value_and_reso(val, obj._creso)
result = Timedelta._from_value_and_reso(val, obj._creso)
else:
return Timestamp._from_value_and_reso(val, obj._creso, tz=None)
result = Timestamp._from_value_and_reso(val, obj._creso, tz=None)

result.__doc__ = self.__doc__

return result

def __set__(self, obj, value):
raise AttributeError(f"{self._name} is not settable.")
Expand All @@ -235,9 +240,74 @@ cdef class _Timestamp(ABCTimestamp):
dayofweek = _Timestamp.day_of_week
dayofyear = _Timestamp.day_of_year

min = MinMaxReso("min")
max = MinMaxReso("max")
resolution = MinMaxReso("resolution") # GH#21336, GH#21365
_docstring_min = """
Returns the minimum bound possible for Timestamp.

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

Returns
-------
Timestamp

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

Examples
--------
>>> pd.Timestamp.min
Timestamp('1677-09-21 00:12:43.145224193')
"""

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

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

Returns
-------
Timestamp

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

Examples
--------
>>> pd.Timestamp.max
Timestamp('2262-04-11 23:47:16.854775807')
"""

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

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

Returns
-------
Timedelta

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

Examples
--------
>>> pd.Timestamp.resolution
Timedelta('0 days 00:00:00.000000001')
"""

min = MinMaxReso("min", _docstring_min)
max = MinMaxReso("max", _docstring_max)
resolution = MinMaxReso("resolution", _docstring_reso) # GH#21336, GH#21365

@property
def value(self) -> int:
Expand Down
Loading