From 7c461b291c45cfa83502c11eb15b2d1c1ba47536 Mon Sep 17 00:00:00 2001 From: Joseph Wagner Date: Tue, 9 May 2017 20:45:55 -0700 Subject: [PATCH 1/2] BUG: select_as_multiple doesn't respect start/stop kwargs GH16209 --- doc/source/whatsnew/v0.21.0.txt | 1 + pandas/io/pytables.py | 7 ++++--- pandas/tests/io/test_pytables.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index 36dffc3d3378b..bb9ad95856875 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -82,6 +82,7 @@ Indexing I/O ^^^ +- Bug in ``HDFStore.select_as_multiple()`` where start/stop arguments were not respected (:issue:`16209`) Plotting diff --git a/pandas/io/pytables.py b/pandas/io/pytables.py index 17bedd016f617..3187d6fb31177 100644 --- a/pandas/io/pytables.py +++ b/pandas/io/pytables.py @@ -826,8 +826,8 @@ def func(_start, _stop, _where): # retrieve the objs, _where is always passed as a set of # coordinates here - objs = [t.read(where=_where, columns=columns, **kwargs) - for t in tbls] + objs = [t.read(where=_where, columns=columns, start=_start, + stop=_stop, **kwargs) for t in tbls] # concat and return return concat(objs, axis=axis, @@ -1420,7 +1420,8 @@ def get_result(self, coordinates=False): # if specified read via coordinates (necessary for multiple selections if coordinates: - where = self.s.read_coordinates(where=self.where) + where = self.s.read_coordinates(where=self.where, start=self.start, + stop=self.stop) else: where = self.where diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index 873bb20b3bba9..ed9ab2aeb2a33 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -4186,6 +4186,20 @@ def test_start_stop_table(self): expected = df.loc[30:40, ['A']] tm.assert_frame_equal(result, expected) + def test_start_stop_multiple(self): + + with ensure_clean_store(self.path) as store: + + df = DataFrame({"foo": [1, 2], "bar": [1, 2]}) + + store.append_to_multiple({'selector': ['foo'], 'data': None}, df, + selector='selector') + result = store.select_as_multiple(['selector', 'data'], + selector='selector', start=0, + stop=1) + expected = df[['foo', 'bar']].iloc[[0]] + tm.assert_frame_equal(result, expected) + def test_start_stop_fixed(self): with ensure_clean_store(self.path) as store: From 6d6764f247bf83de047dde96057f2627ea4f6868 Mon Sep 17 00:00:00 2001 From: Joseph Wagner Date: Tue, 30 May 2017 19:29:20 -0700 Subject: [PATCH 2/2] move whatsnew; minor test fixes (#16209) --- doc/source/whatsnew/v0.20.2.txt | 1 + doc/source/whatsnew/v0.21.0.txt | 1 - pandas/tests/io/test_pytables.py | 3 ++- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v0.20.2.txt b/doc/source/whatsnew/v0.20.2.txt index bca92137891a0..02f70d85ab278 100644 --- a/doc/source/whatsnew/v0.20.2.txt +++ b/doc/source/whatsnew/v0.20.2.txt @@ -51,6 +51,7 @@ I/O - Bug that would force importing of the clipboard routines unnecessarily, potentially causing an import error on startup (:issue:`16288`) +- Bug in ``HDFStore.select_as_multiple()`` where start/stop arguments were not respected (:issue:`16209`) Plotting ^^^^^^^^ diff --git a/doc/source/whatsnew/v0.21.0.txt b/doc/source/whatsnew/v0.21.0.txt index bb9ad95856875..36dffc3d3378b 100644 --- a/doc/source/whatsnew/v0.21.0.txt +++ b/doc/source/whatsnew/v0.21.0.txt @@ -82,7 +82,6 @@ Indexing I/O ^^^ -- Bug in ``HDFStore.select_as_multiple()`` where start/stop arguments were not respected (:issue:`16209`) Plotting diff --git a/pandas/tests/io/test_pytables.py b/pandas/tests/io/test_pytables.py index ed9ab2aeb2a33..0940d978d2b7a 100644 --- a/pandas/tests/io/test_pytables.py +++ b/pandas/tests/io/test_pytables.py @@ -4188,6 +4188,7 @@ def test_start_stop_table(self): def test_start_stop_multiple(self): + # GH 16209 with ensure_clean_store(self.path) as store: df = DataFrame({"foo": [1, 2], "bar": [1, 2]}) @@ -4197,7 +4198,7 @@ def test_start_stop_multiple(self): result = store.select_as_multiple(['selector', 'data'], selector='selector', start=0, stop=1) - expected = df[['foo', 'bar']].iloc[[0]] + expected = df.loc[[0], ['foo', 'bar']] tm.assert_frame_equal(result, expected) def test_start_stop_fixed(self):