@@ -532,10 +532,16 @@ def astype(self, dtype, copy=False, errors='raise', values=None, **kwargs):
532
532
** kwargs )
533
533
534
534
def _astype (self , dtype , copy = False , errors = 'raise' , values = None ,
535
- klass = None , mgr = None , raise_on_error = False , ** kwargs ):
535
+ klass = None , mgr = None , ** kwargs ):
536
536
"""
537
- Coerce to the new type (if copy=True, return a new copy)
538
- raise on an except if raise == True
537
+ Coerce to the new type
538
+
539
+ dtype : str, dtype convertible
540
+ copy : boolean, default False
541
+ copy if indicated
542
+ errors : str, {'raise', 'ignore'}, default 'ignore'
543
+ - ``raise`` : allow exceptions to be raised
544
+ - ``ignore`` : suppress exceptions. On error return original object
539
545
"""
540
546
errors_legal_values = ('raise' , 'ignore' )
541
547
@@ -1248,16 +1254,18 @@ def shift(self, periods, axis=0, mgr=None):
1248
1254
1249
1255
return [self .make_block (new_values , fastpath = True )]
1250
1256
1251
- def eval (self , func , other , raise_on_error = True , try_cast = False , mgr = None ):
1257
+ def eval (self , func , other , errors = 'raise' , try_cast = False , mgr = None ):
1252
1258
"""
1253
1259
evaluate the block; return result block from the result
1254
1260
1255
1261
Parameters
1256
1262
----------
1257
1263
func : how to combine self, other
1258
1264
other : a ndarray/object
1259
- raise_on_error : if True, raise when I can't perform the function,
1260
- False by default (and just return the data that we had coming in)
1265
+ errors : str, {'raise', 'ignore'}, default 'raise'
1266
+ - ``raise`` : allow exceptions to be raised
1267
+ - ``ignore`` : suppress exceptions. On error return original object
1268
+
1261
1269
try_cast : try casting the results to the input type
1262
1270
1263
1271
Returns
@@ -1295,7 +1303,7 @@ def eval(self, func, other, raise_on_error=True, try_cast=False, mgr=None):
1295
1303
except TypeError :
1296
1304
block = self .coerce_to_target_dtype (orig_other )
1297
1305
return block .eval (func , orig_other ,
1298
- raise_on_error = raise_on_error ,
1306
+ errors = errors ,
1299
1307
try_cast = try_cast , mgr = mgr )
1300
1308
1301
1309
# get the result, may need to transpose the other
@@ -1337,7 +1345,7 @@ def get_result(other):
1337
1345
# error handler if we have an issue operating with the function
1338
1346
def handle_error ():
1339
1347
1340
- if raise_on_error :
1348
+ if errors == 'raise' :
1341
1349
# The 'detail' variable is defined in outer scope.
1342
1350
raise TypeError ('Could not operate %s with block values %s' %
1343
1351
(repr (other ), str (detail ))) # noqa
@@ -1383,7 +1391,7 @@ def handle_error():
1383
1391
result = _block_shape (result , ndim = self .ndim )
1384
1392
return [self .make_block (result , fastpath = True , )]
1385
1393
1386
- def where (self , other , cond , align = True , raise_on_error = True ,
1394
+ def where (self , other , cond , align = True , errors = 'raise' ,
1387
1395
try_cast = False , axis = 0 , transpose = False , mgr = None ):
1388
1396
"""
1389
1397
evaluate the block; return result block(s) from the result
@@ -1393,8 +1401,10 @@ def where(self, other, cond, align=True, raise_on_error=True,
1393
1401
other : a ndarray/object
1394
1402
cond : the condition to respect
1395
1403
align : boolean, perform alignment on other/cond
1396
- raise_on_error : if True, raise when I can't perform the function,
1397
- False by default (and just return the data that we had coming in)
1404
+ errors : str, {'raise', 'ignore'}, default 'raise'
1405
+ - ``raise`` : allow exceptions to be raised
1406
+ - ``ignore`` : suppress exceptions. On error return original object
1407
+
1398
1408
axis : int
1399
1409
transpose : boolean
1400
1410
Set to True if self is stored with axes reversed
@@ -1404,6 +1414,7 @@ def where(self, other, cond, align=True, raise_on_error=True,
1404
1414
a new block(s), the result of the func
1405
1415
"""
1406
1416
import pandas .core .computation .expressions as expressions
1417
+ assert errors in ['raise' , 'ignore' ]
1407
1418
1408
1419
values = self .values
1409
1420
orig_other = other
@@ -1436,9 +1447,9 @@ def func(cond, values, other):
1436
1447
1437
1448
try :
1438
1449
return self ._try_coerce_result (expressions .where (
1439
- cond , values , other , raise_on_error = True ))
1450
+ cond , values , other ))
1440
1451
except Exception as detail :
1441
- if raise_on_error :
1452
+ if errors == 'raise' :
1442
1453
raise TypeError ('Could not operate [%s] with block values '
1443
1454
'[%s]' % (repr (other ), str (detail )))
1444
1455
else :
@@ -1454,10 +1465,10 @@ def func(cond, values, other):
1454
1465
except TypeError :
1455
1466
1456
1467
# we cannot coerce, return a compat dtype
1457
- # we are explicity ignoring raise_on_error here
1468
+ # we are explicity ignoring errors
1458
1469
block = self .coerce_to_target_dtype (other )
1459
1470
blocks = block .where (orig_other , cond , align = align ,
1460
- raise_on_error = raise_on_error ,
1471
+ errors = errors ,
1461
1472
try_cast = try_cast , axis = axis ,
1462
1473
transpose = transpose )
1463
1474
return self ._maybe_downcast (blocks , 'infer' )
@@ -2745,7 +2756,7 @@ def sp_index(self):
2745
2756
def kind (self ):
2746
2757
return self .values .kind
2747
2758
2748
- def _astype (self , dtype , copy = False , raise_on_error = True , values = None ,
2759
+ def _astype (self , dtype , copy = False , errors = 'raise' , values = None ,
2749
2760
klass = None , mgr = None , ** kwargs ):
2750
2761
if values is None :
2751
2762
values = self .values
0 commit comments