@@ -531,10 +531,20 @@ def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
531
531
** kwargs )
532
532
533
533
def _astype (self , dtype , copy = False , errors = 'raise' , values = None ,
534
- klass = None , mgr = None , raise_on_error = False , ** kwargs ):
534
+ klass = None , mgr = None , ** kwargs ):
535
535
"""
536
- Coerce to the new type (if copy=True, return a new copy)
537
- raise on an except if raise == True
536
+ Coerce to the new type
537
+
538
+ dtype : str, dtype convertible
539
+ copy : boolean, default False
540
+ copy if indicated
541
+ errors : str, {'raise', 'ignore'}, default 'ignore'
542
+ - ``raise`` : allow exceptions to be raised
543
+ - ``ignore`` : suppress exceptions. On error return original object
544
+
545
+ values :
546
+ klass :
547
+ mgr :
538
548
"""
539
549
errors_legal_values = ('raise' , 'ignore' )
540
550
@@ -1239,16 +1249,18 @@ def shift(self, periods, axis=0, mgr=None):
1239
1249
1240
1250
return [self .make_block (new_values , fastpath = True )]
1241
1251
1242
- def eval (self , func , other , raise_on_error = True , try_cast = False , mgr = None ):
1252
+ def eval (self , func , other , errors = 'raise' , try_cast = False , mgr = None ):
1243
1253
"""
1244
1254
evaluate the block; return result block from the result
1245
1255
1246
1256
Parameters
1247
1257
----------
1248
1258
func : how to combine self, other
1249
1259
other : a ndarray/object
1250
- raise_on_error : if True, raise when I can't perform the function,
1251
- False by default (and just return the data that we had coming in)
1260
+ errors : str, {'raise', 'ignore'}, default 'raise'
1261
+ - ``raise`` : allow exceptions to be raised
1262
+ - ``ignore`` : suppress exceptions. On error return original object
1263
+
1252
1264
try_cast : try casting the results to the input type
1253
1265
1254
1266
Returns
@@ -1286,7 +1298,7 @@ def eval(self, func, other, raise_on_error=True, try_cast=False, mgr=None):
1286
1298
except TypeError :
1287
1299
block = self .coerce_to_target_dtype (orig_other )
1288
1300
return block .eval (func , orig_other ,
1289
- raise_on_error = raise_on_error ,
1301
+ errors = errors ,
1290
1302
try_cast = try_cast , mgr = mgr )
1291
1303
1292
1304
# get the result, may need to transpose the other
@@ -1328,7 +1340,7 @@ def get_result(other):
1328
1340
# error handler if we have an issue operating with the function
1329
1341
def handle_error ():
1330
1342
1331
- if raise_on_error :
1343
+ if errors == 'raise' :
1332
1344
# The 'detail' variable is defined in outer scope.
1333
1345
raise TypeError ('Could not operate %s with block values %s' %
1334
1346
(repr (other ), str (detail ))) # noqa
@@ -1374,7 +1386,7 @@ def handle_error():
1374
1386
result = _block_shape (result , ndim = self .ndim )
1375
1387
return [self .make_block (result , fastpath = True , )]
1376
1388
1377
- def where (self , other , cond , align = True , raise_on_error = True ,
1389
+ def where (self , other , cond , align = True , errors = 'raise' ,
1378
1390
try_cast = False , axis = 0 , transpose = False , mgr = None ):
1379
1391
"""
1380
1392
evaluate the block; return result block(s) from the result
@@ -1384,8 +1396,10 @@ def where(self, other, cond, align=True, raise_on_error=True,
1384
1396
other : a ndarray/object
1385
1397
cond : the condition to respect
1386
1398
align : boolean, perform alignment on other/cond
1387
- raise_on_error : if True, raise when I can't perform the function,
1388
- False by default (and just return the data that we had coming in)
1399
+ errors : str, {'raise', 'ignore'}, default 'raise'
1400
+ - ``raise`` : allow exceptions to be raised
1401
+ - ``ignore`` : suppress exceptions. On error return original object
1402
+
1389
1403
axis : int
1390
1404
transpose : boolean
1391
1405
Set to True if self is stored with axes reversed
@@ -1395,6 +1409,7 @@ def where(self, other, cond, align=True, raise_on_error=True,
1395
1409
a new block(s), the result of the func
1396
1410
"""
1397
1411
import pandas .core .computation .expressions as expressions
1412
+ assert errors in ['raise' , 'ignore' ]
1398
1413
1399
1414
values = self .values
1400
1415
orig_other = other
@@ -1427,9 +1442,9 @@ def func(cond, values, other):
1427
1442
1428
1443
try :
1429
1444
return self ._try_coerce_result (expressions .where (
1430
- cond , values , other , raise_on_error = True ))
1445
+ cond , values , other , errors = 'raise' ))
1431
1446
except Exception as detail :
1432
- if raise_on_error :
1447
+ if errors == 'raise' :
1433
1448
raise TypeError ('Could not operate [%s] with block values '
1434
1449
'[%s]' % (repr (other ), str (detail )))
1435
1450
else :
@@ -1445,10 +1460,10 @@ def func(cond, values, other):
1445
1460
except TypeError :
1446
1461
1447
1462
# we cannot coerce, return a compat dtype
1448
- # we are explicity ignoring raise_on_error here
1463
+ # we are explicity ignoring errors
1449
1464
block = self .coerce_to_target_dtype (other )
1450
1465
blocks = block .where (orig_other , cond , align = align ,
1451
- raise_on_error = raise_on_error ,
1466
+ errors = errors ,
1452
1467
try_cast = try_cast , axis = axis ,
1453
1468
transpose = transpose )
1454
1469
return self ._maybe_downcast (blocks , 'infer' )
@@ -2736,7 +2751,7 @@ def sp_index(self):
2736
2751
def kind (self ):
2737
2752
return self .values .kind
2738
2753
2739
- def _astype (self , dtype , copy = False , raise_on_error = True , values = None ,
2754
+ def _astype (self , dtype , copy = False , errors = 'raise' , values = None ,
2740
2755
klass = None , mgr = None , ** kwargs ):
2741
2756
if values is None :
2742
2757
values = self .values
0 commit comments