Skip to content

Commit e16e893

Browse files
committed
Refactored so Series case uses dtype attribute
1 parent 6d212c7 commit e16e893

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

pandas/core/computation/expressions.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ def _can_use_numexpr(op, op_str, a, b, dtype_check):
8080
# check for dtype compatibility
8181
dtypes = set()
8282
for o in [a, b]:
83-
if hasattr(o, "dtypes"):
84-
# Series implements dtypes, check for dimension count
85-
if o.ndim > 1:
86-
s = o.dtypes.value_counts()
87-
if len(s) > 1:
88-
return False
89-
dtypes |= set(s.index.astype(str))
90-
else:
91-
dtypes |= {o.dtypes.name}
92-
elif isinstance(o, np.ndarray):
83+
# Series implements dtypes, check for dimension count as well
84+
if hasattr(o, "dtypes") and o.ndim > 1:
85+
s = o.dtypes.value_counts()
86+
if len(s) > 1:
87+
return False
88+
dtypes |= set(s.index.astype(str))
89+
# ndarray and Series Case
90+
elif hasattr(o, "dtype"):
9391
dtypes |= {o.dtype.name}
9492

9593
# allowed are a superset
@@ -183,7 +181,7 @@ def _has_bool_dtype(x):
183181

184182

185183
def _bool_arith_check(
186-
op_str, a, b, not_allowed=frozenset(("/", "//", "**")), unsupported=None
184+
op_str, a, b, not_allowed=frozenset(("/", "//", "**")), unsupported=None
187185
):
188186
if unsupported is None:
189187
unsupported = {"+": "|", "*": "&", "-": "^"}

0 commit comments

Comments
 (0)