From 314ed4573d2eb0db88bf7995fc6e11418a5a7498 Mon Sep 17 00:00:00 2001 From: BrenBarn Date: Mon, 12 Oct 2015 09:23:04 -0700 Subject: [PATCH] Fix mistake in Pytables querying with numpy scalar value. Fixes #11283 --- doc/source/whatsnew/v0.17.1.txt | 2 +- pandas/computation/pytables.py | 2 +- pandas/io/tests/test_pytables.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.17.1.txt b/doc/source/whatsnew/v0.17.1.txt index 74ace42eb7e22..47a83e9894521 100755 --- a/doc/source/whatsnew/v0.17.1.txt +++ b/doc/source/whatsnew/v0.17.1.txt @@ -53,7 +53,7 @@ Bug Fixes - Bug in ``.to_latex()`` output broken when the index has a name (:issue: `10660`) - Bug in ``HDFStore.append`` with strings whose encoded length exceded the max unencoded length (:issue:`11234`) - +- Bug in ``HDFStore.select`` when comparing with a numpy scalar in a where clause (:issue:`11283`) diff --git a/pandas/computation/pytables.py b/pandas/computation/pytables.py index bc4e60f70f2b4..1bc5b8b723657 100644 --- a/pandas/computation/pytables.py +++ b/pandas/computation/pytables.py @@ -129,7 +129,7 @@ def conform(self, rhs): """ inplace conform rhs """ if not com.is_list_like(rhs): rhs = [rhs] - if hasattr(self.rhs, 'ravel'): + if isinstance(rhs, np.ndarray): rhs = rhs.ravel() return rhs diff --git a/pandas/io/tests/test_pytables.py b/pandas/io/tests/test_pytables.py index 167170f7cd7c5..6c78f9cf3937c 100644 --- a/pandas/io/tests/test_pytables.py +++ b/pandas/io/tests/test_pytables.py @@ -3049,6 +3049,18 @@ def test_select_dtypes(self): result = store.select( 'df4', where='values>2.0') tm.assert_frame_equal(expected, result) + + # test selection with comparison against numpy scalar + # GH 11283 + with ensure_clean_store(self.path) as store: + df = tm.makeDataFrame() + + expected = df[df['A']>0] + + store.append('df', df, data_columns=True) + np_zero = np.float64(0) + result = store.select('df', where=["A>np_zero"]) + tm.assert_frame_equal(expected, result) def test_select_with_many_inputs(self):