Skip to content

Commit 2b6c977

Browse files
jbrockmendelTomAugspurger
authored andcommitted
op--> opname (pandas-dev#27849)
1 parent 9fd432b commit 2b6c977

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

pandas/core/arrays/categorical.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
)
7878

7979

80-
def _cat_compare_op(op):
80+
def _cat_compare_op(opname):
8181
def f(self, other):
8282
# On python2, you can usually compare any type to any type, and
8383
# Categoricals can be seen as a custom type, but having different
@@ -90,7 +90,7 @@ def f(self, other):
9090
other = lib.item_from_zerodim(other)
9191

9292
if not self.ordered:
93-
if op in ["__lt__", "__gt__", "__le__", "__ge__"]:
93+
if opname in ["__lt__", "__gt__", "__le__", "__ge__"]:
9494
raise TypeError(
9595
"Unordered Categoricals can only compare equality or not"
9696
)
@@ -117,7 +117,7 @@ def f(self, other):
117117
other_codes = other._codes
118118

119119
mask = (self._codes == -1) | (other_codes == -1)
120-
f = getattr(self._codes, op)
120+
f = getattr(self._codes, opname)
121121
ret = f(other_codes)
122122
if mask.any():
123123
# In other series, the leads to False, so do that here too
@@ -127,38 +127,38 @@ def f(self, other):
127127
if is_scalar(other):
128128
if other in self.categories:
129129
i = self.categories.get_loc(other)
130-
ret = getattr(self._codes, op)(i)
130+
ret = getattr(self._codes, opname)(i)
131131

132132
# check for NaN in self
133133
mask = self._codes == -1
134134
ret[mask] = False
135135
return ret
136136
else:
137-
if op == "__eq__":
137+
if opname == "__eq__":
138138
return np.repeat(False, len(self))
139-
elif op == "__ne__":
139+
elif opname == "__ne__":
140140
return np.repeat(True, len(self))
141141
else:
142142
msg = (
143143
"Cannot compare a Categorical for op {op} with a "
144144
"scalar, which is not a category."
145145
)
146-
raise TypeError(msg.format(op=op))
146+
raise TypeError(msg.format(op=opname))
147147
else:
148148

149149
# allow categorical vs object dtype array comparisons for equality
150150
# 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))
153153

154154
msg = (
155155
"Cannot compare a Categorical for op {op} with type {typ}."
156156
"\nIf you want to compare values, use 'np.asarray(cat) "
157157
"<op> other'."
158158
)
159-
raise TypeError(msg.format(op=op, typ=type(other)))
159+
raise TypeError(msg.format(op=opname, typ=type(other)))
160160

161-
f.__name__ = op
161+
f.__name__ = opname
162162

163163
return f
164164

0 commit comments

Comments
 (0)