@@ -721,9 +721,7 @@ def add_flex_arithmetic_methods(cls, flex_arith_method, flex_comp_method=None):
721
721
subtract = new_methods ['sub' ],
722
722
divide = new_methods ['div' ]))
723
723
# opt out of bool flex methods for now
724
- for k in ('ror_' , 'rxor' , 'rand_' ):
725
- if k in new_methods :
726
- new_methods .pop (k )
724
+ assert not any (kname in new_methods for kname in ('ror_' , 'rxor' , 'rand_' ))
727
725
728
726
add_methods (cls , new_methods = new_methods )
729
727
@@ -1080,19 +1078,19 @@ def na_op(x, y):
1080
1078
try :
1081
1079
result = lib .scalar_binop (x , y , op )
1082
1080
except :
1083
- msg = ("cannot compare a dtyped [{dtype}] array "
1084
- "with a scalar of type [{type }]"
1085
- ) .format (dtype = x .dtype , type = type ( y ). __name__ )
1086
- raise TypeError ( msg )
1081
+ raise TypeError ("cannot compare a dtyped [{dtype}] array "
1082
+ "with a scalar of type [{typ }]"
1083
+ .format (dtype = x .dtype ,
1084
+ typ = type ( y ). __name__ ) )
1087
1085
1088
1086
return result
1089
1087
1088
+ fill_int = lambda x : x .fillna (0 )
1089
+ fill_bool = lambda x : x .fillna (False ).astype (bool )
1090
+
1090
1091
def wrapper (self , other ):
1091
1092
is_self_int_dtype = is_integer_dtype (self .dtype )
1092
1093
1093
- fill_int = lambda x : x .fillna (0 )
1094
- fill_bool = lambda x : x .fillna (False ).astype (bool )
1095
-
1096
1094
self , other = _align_method_SERIES (self , other , align_asobject = True )
1097
1095
1098
1096
if isinstance (other , ABCDataFrame ):
@@ -1232,10 +1230,10 @@ def to_series(right):
1232
1230
1233
1231
elif right .ndim == 2 :
1234
1232
if left .shape != right .shape :
1235
- msg = ("Unable to coerce to DataFrame, shape "
1236
- "must be {req_shape}: given {given_shape}"
1237
- ) .format (req_shape = left .shape , given_shape = right . shape )
1238
- raise ValueError ( msg )
1233
+ raise ValueError ("Unable to coerce to DataFrame, shape "
1234
+ "must be {req_shape}: given {given_shape}"
1235
+ .format (req_shape = left .shape ,
1236
+ given_shape = right . shape ) )
1239
1237
1240
1238
right = left ._constructor (right , index = left .index ,
1241
1239
columns = left .columns )
@@ -1293,8 +1291,8 @@ def na_op(x, y):
1293
1291
result [mask ] = op (xrav , y )
1294
1292
else :
1295
1293
raise TypeError ("cannot perform operation {op} between "
1296
- "objects of type {x} and {y}" . format (
1297
- op = name , x = type (x ), y = type (y )))
1294
+ "objects of type {x} and {y}"
1295
+ . format ( op = name , x = type (x ), y = type (y )))
1298
1296
1299
1297
result , changed = maybe_upcast_putmask (result , ~ mask , np .nan )
1300
1298
result = result .reshape (x .shape )
@@ -1355,7 +1353,7 @@ def f(self, other, axis=default_axis, level=None):
1355
1353
if not self ._indexed_same (other ):
1356
1354
self , other = self .align (other , 'outer' ,
1357
1355
level = level , copy = False )
1358
- return self ._compare_frame (other , na_op , str_rep , try_cast = False )
1356
+ return self ._compare_frame (other , na_op , str_rep )
1359
1357
1360
1358
elif isinstance (other , ABCSeries ):
1361
1359
return _combine_series_frame (self , other , na_op ,
@@ -1380,7 +1378,7 @@ def f(self, other):
1380
1378
if not self ._indexed_same (other ):
1381
1379
raise ValueError ('Can only compare identically-labeled '
1382
1380
'DataFrame objects' )
1383
- return self ._compare_frame (other , func , str_rep , try_cast = True )
1381
+ return self ._compare_frame (other , func , str_rep )
1384
1382
1385
1383
elif isinstance (other , ABCSeries ):
1386
1384
return _combine_series_frame (self , other , func ,
@@ -1532,10 +1530,6 @@ def wrapper(self, other):
1532
1530
.format (other = type (other )))
1533
1531
1534
1532
wrapper .__name__ = name
1535
- if name .startswith ("__" ):
1536
- # strip special method names, e.g. `__add__` needs to be `add` when
1537
- # passed to _sparse_series_op
1538
- name = name [2 :- 2 ]
1539
1533
return wrapper
1540
1534
1541
1535
@@ -1568,7 +1562,7 @@ def wrapper(self, other):
1568
1562
dtype = getattr (other , 'dtype' , None )
1569
1563
other = SparseArray (other , fill_value = self .fill_value ,
1570
1564
dtype = dtype )
1571
- return _sparse_array_op (self , other , op , name )
1565
+ return _sparse_array_op (self , other , op , name , series = False )
1572
1566
elif is_scalar (other ):
1573
1567
with np .errstate (all = 'ignore' ):
1574
1568
fill = op (_get_fill (self ), np .asarray (other ))
@@ -1579,8 +1573,6 @@ def wrapper(self, other):
1579
1573
raise TypeError ('operation with {other} not supported'
1580
1574
.format (other = type (other )))
1581
1575
1582
- if name .startswith ("__" ):
1583
- name = name [2 :- 2 ]
1584
1576
wrapper .__name__ = name
1585
1577
return wrapper
1586
1578
@@ -1591,4 +1583,5 @@ def wrapper(self, other):
1591
1583
1592
1584
sparse_series_special_funcs = dict (arith_method = _arith_method_SPARSE_SERIES ,
1593
1585
comp_method = _arith_method_SPARSE_SERIES ,
1594
- bool_method = None )
1586
+ bool_method = _bool_method_SERIES )
1587
+ # TODO: I don't think the functions defined by bool_method are tested
0 commit comments