Skip to content

Commit eb54f49

Browse files
cpcloudjreback
authored andcommitted
BUG: allow single element bool queries
1 parent 0898f39 commit eb54f49

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

doc/source/release.rst

+2
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ Bug Fixes
170170
a datetimelike (:issue:`6152`)
171171
- Fixed a stack overflow bug in ``query``/``eval`` during lexicographic
172172
string comparisons (:issue:`6155`).
173+
- Fixed a bug in ``query`` where the index of a single-element ``Series`` was
174+
being thrown away (:issue:`6148`).
173175

174176
pandas 0.13.0
175177
-------------

pandas/computation/align.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,12 @@ def wrapper(terms):
8181
return _align_core_single_unary_op(terms[0])
8282

8383
term_values = (term.value for term in terms)
84+
8485
# only scalars or indexes
8586
if all(isinstance(term.value, pd.Index) or term.isscalar for term in
8687
terms):
8788
return np.result_type(*term_values), None
8889

89-
# single element ndarrays
90-
all_has_size = all(hasattr(term.value, 'size') for term in terms)
91-
if all_has_size and all(term.value.size == 1 for term in terms):
92-
return np.result_type(*term_values), None
93-
9490
# no pandas objects
9591
if not _any_pandas_objects(terms):
9692
return np.result_type(*term_values), None

pandas/tests/test_frame.py

+14
Original file line numberDiff line numberDiff line change
@@ -12860,6 +12860,20 @@ def test_query_lex_compare_strings(self):
1286012860
for parser, engine in product(PARSERS, ENGINES):
1286112861
yield self.check_query_lex_compare_strings, parser, engine
1286212862

12863+
def check_query_single_element_booleans(self, parser, engine):
12864+
tm.skip_if_no_ne(engine)
12865+
columns = 'bid', 'bidsize', 'ask', 'asksize'
12866+
data = np.random.randint(2, size=(1, len(columns))).astype(bool)
12867+
df = DataFrame(data, columns=columns)
12868+
res = df.query('bid & ask', engine=engine, parser=parser)
12869+
expected = df[df.bid & df.ask]
12870+
assert_frame_equal(res, expected)
12871+
12872+
def test_query_single_element_booleans(self):
12873+
for parser, engine in product(PARSERS, ENGINES):
12874+
yield self.check_query_single_element_booleans, parser, engine
12875+
12876+
1286312877
class TestDataFrameEvalNumExprPandas(tm.TestCase):
1286412878

1286512879
@classmethod

0 commit comments

Comments
 (0)