Skip to content

Commit 4a182d3

Browse files
committed
Merge pull request #11291 from BrenBarn/pytables-fix
Fix mistake in Pytables querying with numpy scalar value. Fixes #11283
2 parents c2aa6a2 + 314ed45 commit 4a182d3

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

doc/source/whatsnew/v0.17.1.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Bug Fixes
5555

5656
- Bug in ``.to_latex()`` output broken when the index has a name (:issue: `10660`)
5757
- Bug in ``HDFStore.append`` with strings whose encoded length exceded the max unencoded length (:issue:`11234`)
58-
58+
- Bug in ``HDFStore.select`` when comparing with a numpy scalar in a where clause (:issue:`11283`)
5959

6060

6161

pandas/computation/pytables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def conform(self, rhs):
129129
""" inplace conform rhs """
130130
if not com.is_list_like(rhs):
131131
rhs = [rhs]
132-
if hasattr(self.rhs, 'ravel'):
132+
if isinstance(rhs, np.ndarray):
133133
rhs = rhs.ravel()
134134
return rhs
135135

pandas/io/tests/test_pytables.py

+12
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,18 @@ def test_select_dtypes(self):
30493049
result = store.select(
30503050
'df4', where='values>2.0')
30513051
tm.assert_frame_equal(expected, result)
3052+
3053+
# test selection with comparison against numpy scalar
3054+
# GH 11283
3055+
with ensure_clean_store(self.path) as store:
3056+
df = tm.makeDataFrame()
3057+
3058+
expected = df[df['A']>0]
3059+
3060+
store.append('df', df, data_columns=True)
3061+
np_zero = np.float64(0)
3062+
result = store.select('df', where=["A>np_zero"])
3063+
tm.assert_frame_equal(expected, result)
30523064

30533065
def test_select_with_many_inputs(self):
30543066

0 commit comments

Comments
 (0)