@@ -104,7 +104,7 @@ def f(self, other):
104
104
105
105
def _panel_arith_method (op , name ):
106
106
@Substitution (op )
107
- def f (self , other , axis = 'items' ):
107
+ def f (self , other , axis = 0 ):
108
108
"""
109
109
Wrapper method for %s
110
110
@@ -123,6 +123,42 @@ def f(self, other, axis='items'):
123
123
f .__name__ = name
124
124
return f
125
125
126
+ def _comp_method (func , name ):
127
+
128
+ def na_op (x , y ):
129
+ try :
130
+ result = func (x , y )
131
+ except TypeError :
132
+ xrav = x .ravel ()
133
+ result = np .empty (x .size , dtype = x .dtype )
134
+ if isinstance (y , np .ndarray ):
135
+ yrav = y .ravel ()
136
+ mask = notnull (xrav ) & notnull (yrav )
137
+ result [mask ] = func (np .array (list (xrav [mask ])),
138
+ np .array (list (yrav [mask ])))
139
+ else :
140
+ mask = notnull (xrav )
141
+ result [mask ] = func (np .array (list (xrav [mask ])), y )
142
+
143
+ if func == operator .ne : # pragma: no cover
144
+ np .putmask (result , - mask , True )
145
+ else :
146
+ np .putmask (result , - mask , False )
147
+ result = result .reshape (x .shape )
148
+
149
+ return result
150
+
151
+ @Appender ('Wrapper for comparison method %s' % name )
152
+ def f (self , other ):
153
+ if isinstance (other , self ._constructor ):
154
+ return self ._compare_constructor (other , func )
155
+ else :
156
+ return self ._combine_const (other , na_op )
157
+
158
+
159
+ f .__name__ = name
160
+
161
+ return f
126
162
127
163
_agg_doc = """
128
164
Return %(desc)s over requested axis
@@ -400,6 +436,49 @@ def __array_wrap__(self, result):
400
436
d ['copy' ] = False
401
437
return self ._constructor (result , ** d )
402
438
439
+ #----------------------------------------------------------------------
440
+ # Comparison methods
441
+
442
+ def _indexed_same (self , other ):
443
+ return all ([ getattr (self ,a ).equals (getattr (other ,a )) for a in self ._AXIS_ORDERS ])
444
+
445
+ def _compare_constructor (self , other , func ):
446
+ new_data = {}
447
+ for col in getattr (self ,self ._info_axis ):
448
+ new_data [col ] = func (self [col ], other [col ])
449
+
450
+ d = self ._construct_axes_dict ()
451
+ d ['copy' ] = False
452
+ return self ._constructor (data = new_data , ** d )
453
+
454
+ # boolean operators
455
+ __and__ = _arith_method (operator .and_ , '__and__' )
456
+ __or__ = _arith_method (operator .or_ , '__or__' )
457
+ __xor__ = _arith_method (operator .xor , '__xor__' )
458
+
459
+ def __neg__ (self ):
460
+ arr = operator .neg (self .values )
461
+ return self ._wrap_array (arr , self .axes , copy = False )
462
+
463
+ def __invert__ (self ):
464
+ arr = operator .inv (self .values )
465
+ return self ._wrap_array (arr , self .axes , copy = False )
466
+
467
+ # Comparison methods
468
+ __eq__ = _comp_method (operator .eq , '__eq__' )
469
+ __ne__ = _comp_method (operator .ne , '__ne__' )
470
+ __lt__ = _comp_method (operator .lt , '__lt__' )
471
+ __gt__ = _comp_method (operator .gt , '__gt__' )
472
+ __le__ = _comp_method (operator .le , '__le__' )
473
+ __ge__ = _comp_method (operator .ge , '__ge__' )
474
+
475
+ eq = _comp_method (operator .eq , 'eq' )
476
+ ne = _comp_method (operator .ne , 'ne' )
477
+ gt = _comp_method (operator .gt , 'gt' )
478
+ lt = _comp_method (operator .lt , 'lt' )
479
+ ge = _comp_method (operator .ge , 'ge' )
480
+ le = _comp_method (operator .le , 'le' )
481
+
403
482
#----------------------------------------------------------------------
404
483
# Magic methods
405
484
@@ -741,7 +820,10 @@ def reindex(self, major=None, minor=None, method=None,
741
820
if (method is None and not self ._is_mixed_type and al <= 3 ):
742
821
items = kwargs .get ('items' )
743
822
if com ._count_not_none (items , major , minor ) == 3 :
744
- return self ._reindex_multi (items , major , minor )
823
+ try :
824
+ return self ._reindex_multi (items , major , minor )
825
+ except :
826
+ pass
745
827
746
828
if major is not None :
747
829
result = result ._reindex_axis (major , method , al - 2 , copy )
@@ -873,12 +955,12 @@ def _combine(self, other, func, axis=0):
873
955
elif isinstance (other , DataFrame ):
874
956
return self ._combine_frame (other , func , axis = axis )
875
957
elif np .isscalar (other ):
876
- new_values = func (self .values , other )
877
- d = self ._construct_axes_dict ()
878
- return self ._constructor (new_values , ** d )
958
+ return self ._combine_const (other , func )
879
959
880
- def __neg__ (self ):
881
- return - 1 * self
960
+ def _combine_const (self , other , func ):
961
+ new_values = func (self .values , other )
962
+ d = self ._construct_axes_dict ()
963
+ return self ._constructor (new_values , ** d )
882
964
883
965
def _combine_frame (self , other , func , axis = 0 ):
884
966
index , columns = self ._get_plane_axes (axis )
0 commit comments