@@ -1844,16 +1844,18 @@ def copy(self, deep=True):
18441844 return self ._constructor (data ).__finalize__ (self )
18451845
18461846 def convert_objects (self , convert_dates = True , convert_numeric = False ,
1847- copy = True ):
1847+ convert_timedeltas = True , copy = True ):
18481848 """
18491849 Attempt to infer better dtype for object columns
18501850
18511851 Parameters
18521852 ----------
1853- convert_dates : if True, attempt to soft convert_dates , if 'coerce',
1853+ convert_dates : if True, attempt to soft convert dates , if 'coerce',
18541854 force conversion (and non-convertibles get NaT)
18551855 convert_numeric : if True attempt to coerce to numbers (including
18561856 strings), non-convertibles get NaN
1857+ convert_timedeltas : if True, attempt to soft convert timedeltas, if 'coerce',
1858+ force conversion (and non-convertibles get NaT)
18571859 copy : Boolean, if True, return copy, default is True
18581860
18591861 Returns
@@ -1863,6 +1865,7 @@ def convert_objects(self, convert_dates=True, convert_numeric=False,
18631865 return self ._constructor (
18641866 self ._data .convert (convert_dates = convert_dates ,
18651867 convert_numeric = convert_numeric ,
1868+ convert_timedeltas = convert_timedeltas ,
18661869 copy = copy )).__finalize__ (self )
18671870
18681871 #----------------------------------------------------------------------
@@ -3174,23 +3177,22 @@ def abs(self):
31743177 -------
31753178 abs: type of caller
31763179 """
3177- obj = np .abs (self )
31783180
31793181 # suprimo numpy 1.6 hacking
3182+ # for timedeltas
31803183 if _np_version_under1p7 :
3184+
3185+ def _convert_timedeltas (x ):
3186+ if x .dtype .kind == 'm' :
3187+ return np .abs (x .view ('i8' )).astype (x .dtype )
3188+ return np .abs (x )
3189+
31813190 if self .ndim == 1 :
3182- if obj .dtype == 'm8[us]' :
3183- obj = obj .astype ('m8[ns]' )
3191+ return _convert_timedeltas (self )
31843192 elif self .ndim == 2 :
3185- def f (x ):
3186- if x .dtype == 'm8[us]' :
3187- x = x .astype ('m8[ns]' )
3188- return x
3189-
3190- if 'm8[us]' in obj .dtypes .values :
3191- obj = obj .apply (f )
3193+ return self .apply (_convert_timedeltas )
31923194
3193- return obj
3195+ return np . abs ( self )
31943196
31953197 def pct_change (self , periods = 1 , fill_method = 'pad' , limit = None , freq = None ,
31963198 ** kwds ):
0 commit comments