77
77
)
78
78
79
79
80
- def _cat_compare_op (op ):
80
+ def _cat_compare_op (opname ):
81
81
def f (self , other ):
82
82
# On python2, you can usually compare any type to any type, and
83
83
# Categoricals can be seen as a custom type, but having different
@@ -90,7 +90,7 @@ def f(self, other):
90
90
other = lib .item_from_zerodim (other )
91
91
92
92
if not self .ordered :
93
- if op in ["__lt__" , "__gt__" , "__le__" , "__ge__" ]:
93
+ if opname in ["__lt__" , "__gt__" , "__le__" , "__ge__" ]:
94
94
raise TypeError (
95
95
"Unordered Categoricals can only compare equality or not"
96
96
)
@@ -117,7 +117,7 @@ def f(self, other):
117
117
other_codes = other ._codes
118
118
119
119
mask = (self ._codes == - 1 ) | (other_codes == - 1 )
120
- f = getattr (self ._codes , op )
120
+ f = getattr (self ._codes , opname )
121
121
ret = f (other_codes )
122
122
if mask .any ():
123
123
# In other series, the leads to False, so do that here too
@@ -127,38 +127,38 @@ def f(self, other):
127
127
if is_scalar (other ):
128
128
if other in self .categories :
129
129
i = self .categories .get_loc (other )
130
- ret = getattr (self ._codes , op )(i )
130
+ ret = getattr (self ._codes , opname )(i )
131
131
132
132
# check for NaN in self
133
133
mask = self ._codes == - 1
134
134
ret [mask ] = False
135
135
return ret
136
136
else :
137
- if op == "__eq__" :
137
+ if opname == "__eq__" :
138
138
return np .repeat (False , len (self ))
139
- elif op == "__ne__" :
139
+ elif opname == "__ne__" :
140
140
return np .repeat (True , len (self ))
141
141
else :
142
142
msg = (
143
143
"Cannot compare a Categorical for op {op} with a "
144
144
"scalar, which is not a category."
145
145
)
146
- raise TypeError (msg .format (op = op ))
146
+ raise TypeError (msg .format (op = opname ))
147
147
else :
148
148
149
149
# allow categorical vs object dtype array comparisons for equality
150
150
# these are only positional comparisons
151
- if op in ["__eq__" , "__ne__" ]:
152
- return getattr (np .array (self ), op )(np .array (other ))
151
+ if opname in ["__eq__" , "__ne__" ]:
152
+ return getattr (np .array (self ), opname )(np .array (other ))
153
153
154
154
msg = (
155
155
"Cannot compare a Categorical for op {op} with type {typ}."
156
156
"\n If you want to compare values, use 'np.asarray(cat) "
157
157
"<op> other'."
158
158
)
159
- raise TypeError (msg .format (op = op , typ = type (other )))
159
+ raise TypeError (msg .format (op = opname , typ = type (other )))
160
160
161
- f .__name__ = op
161
+ f .__name__ = opname
162
162
163
163
return f
164
164
0 commit comments