Skip to content

Commit da836e9

Browse files
committed
TST: more robust tests in HDFStore
TST: print output on exception
1 parent d212666 commit da836e9

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

Diff for: RELEASE.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ pandas 0.11.0
346346
.. _GH2751: https://github.com/pydata/pandas/issues/2751
347347
.. _GH2747: https://github.com/pydata/pandas/issues/2747
348348
.. _GH2816: https://github.com/pydata/pandas/issues/2816
349-
.. _GH3216: https://github.com/pydata/pandas/issues/2816
349+
.. _GH3216: https://github.com/pydata/pandas/issues/3216
350350

351351
pandas 0.10.1
352352
=============

Diff for: pandas/io/pytables.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -453,18 +453,24 @@ def select_as_multiple(self, keys, where=None, selector=None, columns=None, star
453453
tbls = [ self.get_storer(k) for k in keys ]
454454

455455
# validate rows
456-
if tbls[0] is None:
457-
raise Exception("no valid tables to select as multiple")
458-
nrows = tbls[0].nrows
459-
for t in tbls:
460-
if t.nrows != nrows:
461-
raise ValueError("all tables must have exactly the same nrows!")
456+
nrows = None
457+
for t, k in zip(tbls, keys):
458+
if t is None:
459+
raise TypeError("Invalid table [%s]" % k)
462460
if not t.is_table:
463461
raise TypeError("object [%s] is not a table, and cannot be used in all select as multiple" % t.pathname)
464462

463+
if nrows is None:
464+
nrows = t.nrows
465+
elif t.nrows != nrows:
466+
raise ValueError("all tables must have exactly the same nrows!")
467+
465468
# select coordinates from the selector table
466-
c = self.select_as_coordinates(selector, where, start=start, stop=stop)
467-
nrows = len(c)
469+
try:
470+
c = self.select_as_coordinates(selector, where, start=start, stop=stop)
471+
nrows = len(c)
472+
except (Exception), detail:
473+
raise ValueError("invalid selector [%s]" % selector)
468474

469475
def func(_start, _stop):
470476

Diff for: pandas/io/tests/test_pytables.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from pandas.tests.test_frame import assert_frame_equal
1616
from pandas import concat, Timestamp
1717

18+
from numpy.testing.decorators import slow
19+
1820
try:
1921
import tables
2022
except ImportError:
@@ -2177,6 +2179,12 @@ def test_select_as_multiple(self):
21772179
None, where=['A>0', 'B>0'], selector='df1')
21782180
self.assertRaises(Exception, store.select_as_multiple,
21792181
[None], where=['A>0', 'B>0'], selector='df1')
2182+
self.assertRaises(TypeError, store.select_as_multiple,
2183+
['df1','df3'], where=['A>0', 'B>0'], selector='df1')
2184+
self.assertRaises(KeyError, store.select_as_multiple,
2185+
['df3'], where=['A>0', 'B>0'], selector='df1')
2186+
self.assertRaises(ValueError, store.select_as_multiple,
2187+
['df1','df2'], where=['A>0', 'B>0'], selector='df4')
21802188

21812189
# default select
21822190
result = store.select('df1', ['A>0', 'B>0'])
@@ -2195,12 +2203,19 @@ def test_select_as_multiple(self):
21952203
tm.assert_frame_equal(result, expected)
21962204

21972205
# multiple (diff selector)
2198-
result = store.select_as_multiple(['df1', 'df2'], where=[Term(
2199-
'index', '>', df2.index[4])], selector='df2')
2200-
expected = concat([df1, df2], axis=1)
2201-
expected = expected[5:]
2202-
tm.assert_frame_equal(result, expected)
2203-
2206+
try:
2207+
result = store.select_as_multiple(['df1', 'df2'], where=[Term(
2208+
'index', '>', df2.index[4])], selector='df2')
2209+
expected = concat([df1, df2], axis=1)
2210+
expected = expected[5:]
2211+
tm.assert_frame_equal(result, expected)
2212+
except (Exception), detail:
2213+
print "error in select_as_multiple %s" % str(detail)
2214+
print "store: ", store
2215+
print "df1: ", df1
2216+
print "df2: ", df2
2217+
2218+
22042219
# test excpection for diff rows
22052220
store.append('df3', tm.makeTimeDataFrame(nper=50))
22062221
self.assertRaises(ValueError, store.select_as_multiple,

0 commit comments

Comments
 (0)