Skip to content

Commit ac25441

Browse files
committed
Merge branch 'pytables_backwards_compatability' of https://github.com/hhuuggoo/pandas into hhuuggoo-pytables_backwards_compatability
Conflicts: doc/source/release.rst
2 parents 7c1d8a0 + 3ca1afe commit ac25441

File tree

3 files changed

+57
-5
lines changed

3 files changed

+57
-5
lines changed

doc/source/release.rst

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ Bug Fixes
125125
- Bug in take with duplicate columns not consolidated (:issue:`6240`)
126126
- Bug in interpolate changing dtypes (:issue:`6290`)
127127
- Bug in Series.get, was using a buggy access method (:issue:`6383`)
128+
- Bug in hdfstore queries of the form ``where=[('date', '>=', datetime(2013,1,1)), ('date', '<=', datetime(2014,1,1))]`` (:issue:`6313`)
128129

129130
pandas 0.13.1
130131
-------------

pandas/computation/pytables.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,6 @@ def __init__(self, where, op=None, value=None, queryables=None,
488488
self.filter = None
489489
self.terms = None
490490
self._visitor = None
491-
492491
# capture the environement if needed
493492
lcls = dict()
494493
if isinstance(where, Expr):
@@ -497,13 +496,12 @@ def __init__(self, where, op=None, value=None, queryables=None,
497496
where = where.expr
498497

499498
elif isinstance(where, (list, tuple)):
500-
501-
for w in where:
499+
for idx, w in enumerate(where):
502500
if isinstance(w, Expr):
503501
lcls.update(w.env.locals)
504502
else:
505503
w = self.parse_back_compat(w)
506-
504+
where[idx] = w
507505
where = ' & ' .join(["(%s)" % w for w in where])
508506

509507
self.expr = where
@@ -528,7 +526,16 @@ def parse_back_compat(self, w, op=None, value=None):
528526
warnings.warn("passing a dict to Expr is deprecated, "
529527
"pass the where as a single string",
530528
DeprecationWarning)
531-
529+
if isinstance(w, tuple):
530+
if len(w) == 2:
531+
w, value = w
532+
op = '=='
533+
elif len(w) == 3:
534+
w, op, value = w
535+
warnings.warn("passing a tuple into Expr is deprecated, "
536+
"pass the where as a single string",
537+
DeprecationWarning)
538+
532539
if op is not None:
533540
if not isinstance(w, string_types):
534541
raise TypeError(

pandas/io/tests/test_pytables.py

+44
Original file line numberDiff line numberDiff line change
@@ -2474,6 +2474,50 @@ def test_term_compat(self):
24742474
expected = wp.loc[:,:,['A','B']]
24752475
assert_panel_equal(result, expected)
24762476

2477+
def test_backwards_compat_without_term_object(self):
2478+
with ensure_clean_store(self.path) as store:
2479+
2480+
wp = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
2481+
major_axis=date_range('1/1/2000', periods=5),
2482+
minor_axis=['A', 'B', 'C', 'D'])
2483+
store.append('wp',wp)
2484+
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
2485+
result = store.select('wp', [('major_axis>20000102'),
2486+
('minor_axis', '=', ['A','B']) ])
2487+
expected = wp.loc[:,wp.major_axis>Timestamp('20000102'),['A','B']]
2488+
assert_panel_equal(result, expected)
2489+
2490+
store.remove('wp', ('major_axis>20000103'))
2491+
result = store.select('wp')
2492+
expected = wp.loc[:,wp.major_axis<=Timestamp('20000103'),:]
2493+
assert_panel_equal(result, expected)
2494+
2495+
with ensure_clean_store(self.path) as store:
2496+
2497+
wp = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
2498+
major_axis=date_range('1/1/2000', periods=5),
2499+
minor_axis=['A', 'B', 'C', 'D'])
2500+
store.append('wp',wp)
2501+
2502+
# stringified datetimes
2503+
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
2504+
result = store.select('wp', [('major_axis','>',datetime.datetime(2000,1,2))])
2505+
expected = wp.loc[:,wp.major_axis>Timestamp('20000102')]
2506+
assert_panel_equal(result, expected)
2507+
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
2508+
result = store.select('wp', [('major_axis','>',datetime.datetime(2000,1,2,0,0))])
2509+
expected = wp.loc[:,wp.major_axis>Timestamp('20000102')]
2510+
assert_panel_equal(result, expected)
2511+
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
2512+
result = store.select('wp', [('major_axis','=',[datetime.datetime(2000,1,2,0,0),
2513+
datetime.datetime(2000,1,3,0,0)])])
2514+
expected = wp.loc[:,[Timestamp('20000102'),Timestamp('20000103')]]
2515+
assert_panel_equal(result, expected)
2516+
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
2517+
result = store.select('wp', [('minor_axis','=',['A','B'])])
2518+
expected = wp.loc[:,:,['A','B']]
2519+
assert_panel_equal(result, expected)
2520+
24772521
def test_same_name_scoping(self):
24782522

24792523
with ensure_clean_store(self.path) as store:

0 commit comments

Comments
 (0)