diff --git a/pandas/_libs/tslibs/nattype.pyx b/pandas/_libs/tslibs/nattype.pyx index f2de3fda3be15..53ed507f41eac 100644 --- a/pandas/_libs/tslibs/nattype.pyx +++ b/pandas/_libs/tslibs/nattype.pyx @@ -207,7 +207,7 @@ cdef class _NaT(datetime): def total_seconds(self): """ - Total duration of timedelta in seconds (to ns precision) + Total duration of timedelta in seconds (to ns precision). """ # GH#10939 return np.nan diff --git a/pandas/_libs/tslibs/timedeltas.pyx b/pandas/_libs/tslibs/timedeltas.pyx index 0a19d8749fc7c..ac4274c815503 100644 --- a/pandas/_libs/tslibs/timedeltas.pyx +++ b/pandas/_libs/tslibs/timedeltas.pyx @@ -815,28 +815,48 @@ cdef class _Timedelta(timedelta): cpdef timedelta to_pytimedelta(_Timedelta self): """ - return an actual datetime.timedelta object - note: we lose nanosecond resolution if any + Convert a pandas Timedelta object into a python timedelta object. + + Timedelta objects are internally saved as numpy datetime64[ns] dtype. + Use to_pytimedelta() to convert to object dtype. + + Returns + ------- + datetime.timedelta or numpy.array of datetime.timedelta + + See Also + -------- + to_timedelta : Convert argument to Timedelta type. + + Notes + ----- + Any nanosecond resolution will be lost. """ return timedelta(microseconds=int(self.value) / 1000) def to_timedelta64(self): - """ Returns a numpy.timedelta64 object with 'ns' precision """ + """ + Return a numpy.timedelta64 object with 'ns' precision. + """ return np.timedelta64(self.value, 'ns') def total_seconds(self): """ - Total duration of timedelta in seconds (to ns precision) + Total duration of timedelta in seconds (to ns precision). """ return self.value / 1e9 def view(self, dtype): - """ array view compat """ + """ + Array view compatibility. + """ return np.timedelta64(self.value).view(dtype) @property def components(self): - """ Return a Components NamedTuple-like """ + """ + Return a components namedtuple-like. + """ self._ensure_components() # return the named tuple return Components(self._d, self._h, self._m, self._s, @@ -1135,8 +1155,8 @@ class Timedelta(_Timedelta): Notes ----- The ``.value`` attribute is always in ns. - """ + def __new__(cls, object value=_no_input, unit=None, **kwargs): cdef _Timedelta td_base diff --git a/pandas/_libs/tslibs/timestamps.pyx b/pandas/_libs/tslibs/timestamps.pyx index a9be60214080a..bcac0d51ee034 100644 --- a/pandas/_libs/tslibs/timestamps.pyx +++ b/pandas/_libs/tslibs/timestamps.pyx @@ -340,7 +340,9 @@ cdef class _Timestamp(datetime): self.microsecond, self.tzinfo) cpdef to_datetime64(self): - """ Returns a numpy.datetime64 object with 'ns' precision """ + """ + Return a numpy.datetime64 object with 'ns' precision. + """ return np.datetime64(self.value, 'ns') def __add__(self, other): @@ -526,7 +528,8 @@ cdef class _Timestamp(datetime): class Timestamp(_Timestamp): - """Pandas replacement for datetime.datetime + """ + Pandas replacement for python datetime.datetime object. Timestamp is the pandas equivalent of python's Datetime and is interchangeable with it in most cases. It's the type used @@ -536,9 +539,9 @@ class Timestamp(_Timestamp): Parameters ---------- ts_input : datetime-like, str, int, float - Value to be converted to Timestamp + Value to be converted to Timestamp. freq : str, DateOffset - Offset which Timestamp will have + Offset which Timestamp will have. tz : str, pytz.timezone, dateutil.tz.tzfile or None Time zone for time which Timestamp will have. unit : str