@@ -532,10 +532,20 @@ 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
545
+
546
+ values :
547
+ klass :
548
+ mgr :
539
549
"""
540
550
errors_legal_values = ('raise' , 'ignore' )
541
551
@@ -1248,16 +1258,18 @@ def shift(self, periods, axis=0, mgr=None):
1248
1258
1249
1259
return [self .make_block (new_values , fastpath = True )]
1250
1260
1251
- def eval (self , func , other , raise_on_error = True , try_cast = False , mgr = None ):
1261
+ def eval (self , func , other , errors = 'raise' , try_cast = False , mgr = None ):
1252
1262
"""
1253
1263
evaluate the block; return result block from the result
1254
1264
1255
1265
Parameters
1256
1266
----------
1257
1267
func : how to combine self, other
1258
1268
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)
1269
+ errors : str, {'raise', 'ignore'}, default 'raise'
1270
+ - ``raise`` : allow exceptions to be raised
1271
+ - ``ignore`` : suppress exceptions. On error return original object
1272
+
1261
1273
try_cast : try casting the results to the input type
1262
1274
1263
1275
Returns
@@ -1295,7 +1307,7 @@ def eval(self, func, other, raise_on_error=True, try_cast=False, mgr=None):
1295
1307
except TypeError :
1296
1308
block = self .coerce_to_target_dtype (orig_other )
1297
1309
return block .eval (func , orig_other ,
1298
- raise_on_error = raise_on_error ,
1310
+ errors = errors ,
1299
1311
try_cast = try_cast , mgr = mgr )
1300
1312
1301
1313
# get the result, may need to transpose the other
@@ -1337,7 +1349,7 @@ def get_result(other):
1337
1349
# error handler if we have an issue operating with the function
1338
1350
def handle_error ():
1339
1351
1340
- if raise_on_error :
1352
+ if errors == 'raise' :
1341
1353
# The 'detail' variable is defined in outer scope.
1342
1354
raise TypeError ('Could not operate %s with block values %s' %
1343
1355
(repr (other ), str (detail ))) # noqa
@@ -1383,7 +1395,7 @@ def handle_error():
1383
1395
result = _block_shape (result , ndim = self .ndim )
1384
1396
return [self .make_block (result , fastpath = True , )]
1385
1397
1386
- def where (self , other , cond , align = True , raise_on_error = True ,
1398
+ def where (self , other , cond , align = True , errors = 'raise' ,
1387
1399
try_cast = False , axis = 0 , transpose = False , mgr = None ):
1388
1400
"""
1389
1401
evaluate the block; return result block(s) from the result
@@ -1393,8 +1405,10 @@ def where(self, other, cond, align=True, raise_on_error=True,
1393
1405
other : a ndarray/object
1394
1406
cond : the condition to respect
1395
1407
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)
1408
+ errors : str, {'raise', 'ignore'}, default 'raise'
1409
+ - ``raise`` : allow exceptions to be raised
1410
+ - ``ignore`` : suppress exceptions. On error return original object
1411
+
1398
1412
axis : int
1399
1413
transpose : boolean
1400
1414
Set to True if self is stored with axes reversed
@@ -1404,6 +1418,7 @@ def where(self, other, cond, align=True, raise_on_error=True,
1404
1418
a new block(s), the result of the func
1405
1419
"""
1406
1420
import pandas .core .computation .expressions as expressions
1421
+ assert errors in ['raise' , 'ignore' ]
1407
1422
1408
1423
values = self .values
1409
1424
orig_other = other
@@ -1436,9 +1451,9 @@ def func(cond, values, other):
1436
1451
1437
1452
try :
1438
1453
return self ._try_coerce_result (expressions .where (
1439
- cond , values , other , raise_on_error = True ))
1454
+ cond , values , other ))
1440
1455
except Exception as detail :
1441
- if raise_on_error :
1456
+ if errors == 'raise' :
1442
1457
raise TypeError ('Could not operate [%s] with block values '
1443
1458
'[%s]' % (repr (other ), str (detail )))
1444
1459
else :
@@ -1454,10 +1469,10 @@ def func(cond, values, other):
1454
1469
except TypeError :
1455
1470
1456
1471
# we cannot coerce, return a compat dtype
1457
- # we are explicity ignoring raise_on_error here
1472
+ # we are explicity ignoring errors
1458
1473
block = self .coerce_to_target_dtype (other )
1459
1474
blocks = block .where (orig_other , cond , align = align ,
1460
- raise_on_error = raise_on_error ,
1475
+ errors = errors ,
1461
1476
try_cast = try_cast , axis = axis ,
1462
1477
transpose = transpose )
1463
1478
return self ._maybe_downcast (blocks , 'infer' )
@@ -2745,7 +2760,7 @@ def sp_index(self):
2745
2760
def kind (self ):
2746
2761
return self .values .kind
2747
2762
2748
- def _astype (self , dtype , copy = False , raise_on_error = True , values = None ,
2763
+ def _astype (self , dtype , copy = False , errors = 'raise' , values = None ,
2749
2764
klass = None , mgr = None , ** kwargs ):
2750
2765
if values is None :
2751
2766
values = self .values
0 commit comments