Skip to content

Commit fd14180

Browse files
committed
reflect review
1 parent 43e4953 commit fd14180

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

pandas/core/computation/expressions.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import warnings
1010
import numpy as np
11+
from pandas.core.dtypes.generic import ABCDataFrame
1112

1213
import pandas.core.common as com
1314
from pandas.core.computation.check import _NUMEXPR_INSTALLED
@@ -158,13 +159,11 @@ def _where_numexpr(cond, a, b):
158159

159160

160161
def _has_bool_dtype(x):
161-
try:
162-
if not isinstance(x.dtype, np.dtype):
163-
x = x.rename(columns={'dtype': 'temporary_dtype'})
164-
return x.dtype == bool
165-
except AttributeError:
162+
if isinstance(x, ABCDataFrame):
163+
return 'bool' in x.dtypes
164+
else:
166165
try:
167-
return 'bool' in x.dtypes
166+
return x.dtype == bool
168167
except AttributeError:
169168
return isinstance(x, (bool, np.bool_))
170169

pandas/tests/test_expressions.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
_integer2 = DataFrame(np.random.randint(1, 100, size=(101, 4)),
3737
columns=list('ABCD'), dtype='int64')
3838

39-
4039
with catch_warnings(record=True):
4140
_frame_panel = Panel(dict(ItemA=_frame.copy(),
4241
ItemB=(_frame.copy() + 3),
@@ -443,18 +442,15 @@ def test_bool_ops_warn_on_arithmetic(self):
443442
e = fe(df, True)
444443
tm.assert_frame_equal(r, e)
445444

446-
def test_bool_ops_column_name_dtype(self):
445+
def test_has_bool_ops_column_name_dtype(self, eq, ne):
447446
# GH 22383 - .ne fails if columns containing column name 'dtype'
448447
df_has_error = DataFrame([[0, 1, 2, 'aa'], [0, 1, 2, 'aa'],
449448
[0, 1, 5, 'bb'], [0, 1, 5, 'bb'],
450449
[0, 1, 5, 'bb'], ['cc', 4, 4, 4]],
451450
columns=['a', 'b', 'c', 'dtype'])
452-
df = DataFrame([[0, 1, 2, 'aa'], [0, 1, 2, 'aa'],
453-
[0, 1, 5, 'bb'], [0, 1, 5, 'bb'],
454-
[0, 1, 5, 'bb'], ['cc', 4, 4, 4]],
455-
columns=['a', 'b', 'c', 'd'])
456-
result = df_has_error.loc[:, ['a', 'dtype']].ne(df_has_error.loc[:,
457-
['a', 'dtype']])
458-
assert_frame_equal(result,
459-
df.loc[:, ['a', 'd']].ne(df.loc[:, ['a', 'd']]).
460-
rename({'d': 'dtype'}, axis=1))
451+
expected = DataFrame([[False, False], [False, False],
452+
[False, False], [False, False]],
453+
columns=["a", "dtype"])
454+
assert_frame_equal(expected,
455+
df_has_error.loc[:, ['a', 'dtype']].
456+
ne(df_has_error.loc[:, ['a', 'dtype']]))

0 commit comments

Comments
 (0)