Skip to content

Commit

Permalink
DOC: fix PR09,PR08 errors for pandas.Timestamp
Browse files Browse the repository at this point in the history
this also involves editing the NaT type class
and Timedelta class. this is because there is
a validation which enforces all of these classes
to have the same docstrings

closes pandas-dev#28673
  • Loading branch information
Josiah Baker committed Oct 4, 2019
1 parent 069e124 commit c0f99e2
Show file tree
Hide file tree
Showing 3 changed files with 191 additions and 156 deletions.
168 changes: 92 additions & 76 deletions pandas/_libs/tslibs/nattype.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ class NaTType(_NaT):
Parameters
----------
locale : string, default None (English locale)
locale determining the language in which to return the month name
Locale determining the language in which to return the month name.
Returns
-------
Expand All @@ -411,7 +411,7 @@ class NaTType(_NaT):
Parameters
----------
locale : string, default None (English locale)
locale determining the language in which to return the day name
Locale determining the language in which to return the day name.
Returns
-------
Expand Down Expand Up @@ -509,11 +509,11 @@ class NaTType(_NaT):
Parameters
----------
ordinal : int
date corresponding to a proleptic Gregorian ordinal
Date corresponding to a proleptic Gregorian ordinal.
freq : str, DateOffset
Offset which Timestamp will have
Offset to apply to the Timestamp.
tz : str, pytz.timezone, dateutil.tz.tzfile or None
Time zone for time which Timestamp will have.
Time zone for the Timestamp.
""")

# _nat_methods
Expand All @@ -534,7 +534,7 @@ class NaTType(_NaT):
Parameters
----------
tz : str or timezone object, default None
Timezone to localize to
Timezone to localize to.
""")
today = _make_nat_func('today', # noqa:E128
"""
Expand All @@ -547,35 +547,38 @@ class NaTType(_NaT):
Parameters
----------
tz : str or timezone object, default None
Timezone to localize to
Timezone to localize to.
""")
round = _make_nat_func('round', # noqa:E128
"""
Round the Timestamp to the specified resolution.
Parameters
----------
freq : a freq string indicating the rounding resolution
ambiguous : bool, 'NaT', default 'raise'
- bool contains flags to determine if time is dst or not (note
that this flag is only applicable for ambiguous fall dst dates)
- 'NaT' will return NaT for an ambiguous time
- 'raise' will raise an AmbiguousTimeError for an ambiguous time
freq : str
Frequency string indicating the rounding resolution.
ambiguous : bool or {'raise', 'NaT'}, default 'raise'
The behavior is as follows:
* bool contains flags to determine if time is dst or not (note
that this flag is only applicable for ambiguous fall dst dates).
* 'NaT' will return NaT for an ambiguous time.
* 'raise' will raise an AmbiguousTimeError for an ambiguous time.
.. versionadded:: 0.24.0
nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, \
default 'raise'
nonexistent : {'raise', 'shift_forward', 'shift_backward, 'NaT', \
timedelta}, default 'raise'
A nonexistent time does not exist in a particular timezone
where clocks moved forward due to DST.
- 'shift_forward' will shift the nonexistent time forward to the
closest existing time
- 'shift_backward' will shift the nonexistent time backward to the
closest existing time
- 'NaT' will return NaT where there are nonexistent times
- timedelta objects will shift nonexistent times by the timedelta
- 'raise' will raise an NonExistentTimeError if there are
nonexistent times
* 'shift_forward' will shift the nonexistent time forward to the
closest existing time.
* 'shift_backward' will shift the nonexistent time backward to the
closest existing time.
* 'NaT' will return NaT where there are nonexistent times.
* timedelta objects will shift nonexistent times by the timedelta.
* 'raise' will raise an NonExistentTimeError if there are
nonexistent times.
.. versionadded:: 0.24.0
Expand All @@ -585,75 +588,81 @@ default 'raise'
Raises
------
ValueError if the freq cannot be converted
ValueError if the freq cannot be converted.
""")
floor = _make_nat_func('floor', # noqa:E128
"""
return a new Timestamp floored to this resolution.
Parameters
----------
freq : a freq string indicating the flooring resolution
ambiguous : bool, 'NaT', default 'raise'
- bool contains flags to determine if time is dst or not (note
that this flag is only applicable for ambiguous fall dst dates)
- 'NaT' will return NaT for an ambiguous time
- 'raise' will raise an AmbiguousTimeError for an ambiguous time
freq : str
Frequency string indicating the flooring resolution.
ambiguous : bool or {'raise', 'NaT'}, default 'raise'
The behavior is as follows:
* bool contains flags to determine if time is dst or not (note
that this flag is only applicable for ambiguous fall dst dates).
* 'NaT' will return NaT for an ambiguous time.
* 'raise' will raise an AmbiguousTimeError for an ambiguous time.
.. versionadded:: 0.24.0
nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, \
default 'raise'
nonexistent : {'raise', 'shift_forward', 'shift_backward, 'NaT', \
timedelta}, default 'raise'
A nonexistent time does not exist in a particular timezone
where clocks moved forward due to DST.
- 'shift_forward' will shift the nonexistent time forward to the
closest existing time
- 'shift_backward' will shift the nonexistent time backward to the
closest existing time
- 'NaT' will return NaT where there are nonexistent times
- timedelta objects will shift nonexistent times by the timedelta
- 'raise' will raise an NonExistentTimeError if there are
nonexistent times
* 'shift_forward' will shift the nonexistent time forward to the
closest existing time.
* 'shift_backward' will shift the nonexistent time backward to the
closest existing time.
* 'NaT' will return NaT where there are nonexistent times.
* timedelta objects will shift nonexistent times by the timedelta.
* 'raise' will raise an NonExistentTimeError if there are
nonexistent times.
.. versionadded:: 0.24.0
Raises
------
ValueError if the freq cannot be converted
ValueError if the freq cannot be converted.
""")
ceil = _make_nat_func('ceil', # noqa:E128
"""
return a new Timestamp ceiled to this resolution.
Parameters
----------
freq : a freq string indicating the ceiling resolution
ambiguous : bool, 'NaT', default 'raise'
- bool contains flags to determine if time is dst or not (note
that this flag is only applicable for ambiguous fall dst dates)
- 'NaT' will return NaT for an ambiguous time
- 'raise' will raise an AmbiguousTimeError for an ambiguous time
freq : str
Frequency string indicating the ceiling resolution.
ambiguous : bool or {'raise', 'NaT'}, default 'raise'
The behavior is as follows:
* bool contains flags to determine if time is dst or not (note
that this flag is only applicable for ambiguous fall dst dates).
* 'NaT' will return NaT for an ambiguous time.
* 'raise' will raise an AmbiguousTimeError for an ambiguous time.
.. versionadded:: 0.24.0
nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, \
default 'raise'
nonexistent : {'raise', 'shift_forward', 'shift_backward, 'NaT', \
timedelta}, default 'raise'
A nonexistent time does not exist in a particular timezone
where clocks moved forward due to DST.
- 'shift_forward' will shift the nonexistent time forward to the
closest existing time
- 'shift_backward' will shift the nonexistent time backward to the
closest existing time
- 'NaT' will return NaT where there are nonexistent times
- timedelta objects will shift nonexistent times by the timedelta
- 'raise' will raise an NonExistentTimeError if there are
nonexistent times
* 'shift_forward' will shift the nonexistent time forward to the
closest existing time.
* 'shift_backward' will shift the nonexistent time backward to the
closest existing time.
* 'NaT' will return NaT where there are nonexistent times.
* timedelta objects will shift nonexistent times by the timedelta.
* 'raise' will raise an NonExistentTimeError if there are
nonexistent times.
.. versionadded:: 0.24.0
Raises
------
ValueError if the freq cannot be converted
ValueError if the freq cannot be converted.
""")

tz_convert = _make_nat_func('tz_convert', # noqa:E128
Expand Down Expand Up @@ -694,35 +703,42 @@ default 'raise'
`ambiguous` parameter dictates how ambiguous times should be
handled.
- bool contains flags to determine if time is dst or not (note
that this flag is only applicable for ambiguous fall dst dates)
- 'NaT' will return NaT for an ambiguous time
- 'raise' will raise an AmbiguousTimeError for an ambiguous time
The behavior is as follows:
* bool contains flags to determine if time is dst or not (note
that this flag is only applicable for ambiguous fall dst dates).
* 'NaT' will return NaT for an ambiguous time.
* 'raise' will raise an AmbiguousTimeError for an ambiguous time.
nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, \
default 'raise'
A nonexistent time does not exist in a particular timezone
where clocks moved forward due to DST.
- 'shift_forward' will shift the nonexistent time forward to the
closest existing time
- 'shift_backward' will shift the nonexistent time backward to the
closest existing time
- 'NaT' will return NaT where there are nonexistent times
- timedelta objects will shift nonexistent times by the timedelta
- 'raise' will raise an NonExistentTimeError if there are
nonexistent times
The behavior is as follows:
.. versionadded:: 0.24.0
* 'shift_forward' will shift the nonexistent time forward to the
closest existing time.
* 'shift_backward' will shift the nonexistent time backward to the
closest existing time.
* 'NaT' will return NaT where there are nonexistent times.
* timedelta objects will shift nonexistent times by the timedelta.
* 'raise' will raise an NonExistentTimeError if there are
nonexistent times.
.. versionadded:: 0.24.0
errors : 'raise', 'coerce', default None
- 'raise' will raise a NonExistentTimeError if a timestamp is not
valid in the specified timezone (e.g. due to a transition from
or to DST time). Use ``nonexistent='raise'`` instead.
- 'coerce' will return NaT if the timestamp can not be converted
Determine how errors should be handled.
The behavior is as follows:
* 'raise' will raise a NonExistentTimeError if a timestamp is not
valid in the specified timezone (e.g. due to a transition from
or to DST time). Use ``nonexistent='raise'`` instead.
* 'coerce' will return NaT if the timestamp can not be converted
into the specified timezone. Use ``nonexistent='NaT'`` instead.
.. deprecated:: 0.24.0
.. deprecated:: 0.24.0
Returns
-------
Expand Down
11 changes: 7 additions & 4 deletions pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ class Timedelta(_Timedelta):
'm', 'minute', 'min', 'minutes', 'T', 'S', 'seconds', 'sec', 'second',
'ms', 'milliseconds', 'millisecond', 'milli', 'millis', 'L',
'us', 'microseconds', 'microsecond', 'micro', 'micros', 'U',
'ns', 'nanoseconds', 'nano', 'nanos', 'nanosecond', 'N'}
'ns', 'nanoseconds', 'nano', 'nanos', 'nanosecond', 'N'}.
**kwargs
Available kwargs: {days, seconds, microseconds,
milliseconds, minutes, hours, weeks}.
Expand Down Expand Up @@ -1323,7 +1323,8 @@ class Timedelta(_Timedelta):
Parameters
----------
freq : a freq string indicating the rounding resolution
freq : str
Frequency string indicating the rounding resolution.
Returns
-------
Expand All @@ -1341,7 +1342,8 @@ class Timedelta(_Timedelta):
Parameters
----------
freq : a freq string indicating the flooring resolution
freq : str
Frequency string indicating the flooring resolution.
"""
return self._round(freq, np.floor)

Expand All @@ -1351,7 +1353,8 @@ class Timedelta(_Timedelta):
Parameters
----------
freq : a freq string indicating the ceiling resolution
freq : str
Frequency string indicating the ceiling resolution.
"""
return self._round(freq, np.ceil)

Expand Down
Loading

0 comments on commit c0f99e2

Please sign in to comment.