@@ -815,13 +815,29 @@ cdef class _Timedelta(timedelta):
815
815
816
816
cpdef timedelta to_pytimedelta(_Timedelta self ):
817
817
"""
818
- return an actual datetime.timedelta object
819
- note: we lose nanosecond resolution if any
818
+ Convert a pandas Timedelta object into a python timedelta object.
819
+
820
+ Timedelta objects are internally saved as numpy datetime64[ns] dtype.
821
+ Use to_pytimedelta() to convert to object dtype.
822
+
823
+ Returns
824
+ -------
825
+ datetime.timedelta or numpy.array of datetime.timedelta
826
+
827
+ See Also
828
+ --------
829
+ to_timedelta : Convert argument to Timedelta type.
830
+
831
+ Notes
832
+ -----
833
+ Any nanosecond resolution will be lost.
820
834
"""
821
835
return timedelta(microseconds = int (self .value) / 1000 )
822
836
823
837
def to_timedelta64 (self ):
824
- """ Returns a numpy.timedelta64 object with 'ns' precision """
838
+ """
839
+ Return a numpy.timedelta64 object with 'ns' precision.
840
+ """
825
841
return np.timedelta64(self .value, ' ns' )
826
842
827
843
def to_numpy (self , dtype = None , copy = False ):
@@ -846,17 +862,21 @@ cdef class _Timedelta(timedelta):
846
862
847
863
def total_seconds (self ):
848
864
"""
849
- Total duration of timedelta in seconds (to ns precision)
865
+ Total duration of timedelta in seconds (to ns precision).
850
866
"""
851
867
return self .value / 1e9
852
868
853
869
def view (self , dtype ):
854
- """ array view compat """
870
+ """
871
+ Array view compatibility.
872
+ """
855
873
return np.timedelta64(self .value).view(dtype)
856
874
857
875
@property
858
876
def components (self ):
859
- """ Return a Components NamedTuple-like """
877
+ """
878
+ Return a components namedtuple-like.
879
+ """
860
880
self ._ensure_components()
861
881
# return the named tuple
862
882
return Components(self ._d, self ._h, self ._m, self ._s,
@@ -1157,6 +1177,7 @@ class Timedelta(_Timedelta):
1157
1177
-----
1158
1178
The ``.value`` attribute is always in ns.
1159
1179
"""
1180
+
1160
1181
def __new__ (cls , object value = _no_input, unit = None , **kwargs ):
1161
1182
cdef _Timedelta td_base
1162
1183
0 commit comments