@@ -1844,16 +1844,18 @@ def copy(self, deep=True):
1844
1844
return self ._constructor (data ).__finalize__ (self )
1845
1845
1846
1846
def convert_objects (self , convert_dates = True , convert_numeric = False ,
1847
- copy = True ):
1847
+ convert_timedeltas = True , copy = True ):
1848
1848
"""
1849
1849
Attempt to infer better dtype for object columns
1850
1850
1851
1851
Parameters
1852
1852
----------
1853
- convert_dates : if True, attempt to soft convert_dates , if 'coerce',
1853
+ convert_dates : if True, attempt to soft convert dates , if 'coerce',
1854
1854
force conversion (and non-convertibles get NaT)
1855
1855
convert_numeric : if True attempt to coerce to numbers (including
1856
1856
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)
1857
1859
copy : Boolean, if True, return copy, default is True
1858
1860
1859
1861
Returns
@@ -1863,6 +1865,7 @@ def convert_objects(self, convert_dates=True, convert_numeric=False,
1863
1865
return self ._constructor (
1864
1866
self ._data .convert (convert_dates = convert_dates ,
1865
1867
convert_numeric = convert_numeric ,
1868
+ convert_timedeltas = convert_timedeltas ,
1866
1869
copy = copy )).__finalize__ (self )
1867
1870
1868
1871
#----------------------------------------------------------------------
@@ -3174,23 +3177,22 @@ def abs(self):
3174
3177
-------
3175
3178
abs: type of caller
3176
3179
"""
3177
- obj = np .abs (self )
3178
3180
3179
3181
# suprimo numpy 1.6 hacking
3182
+ # for timedeltas
3180
3183
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
+
3181
3190
if self .ndim == 1 :
3182
- if obj .dtype == 'm8[us]' :
3183
- obj = obj .astype ('m8[ns]' )
3191
+ return _convert_timedeltas (self )
3184
3192
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 )
3192
3194
3193
- return obj
3195
+ return np . abs ( self )
3194
3196
3195
3197
def pct_change (self , periods = 1 , fill_method = 'pad' , limit = None , freq = None ,
3196
3198
** kwds ):
0 commit comments