Skip to content

FIX: hdfstore queries of the form where=[('date', '>=', datetime(2013,1,... #6313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Bug Fixes
keys not in the values to be replaced (:issue:`6342`)
- Bug in take with duplicate columns not consolidated (:issue:`6240`)
- Bug in interpolate changing dtypes (:issue:`6290`)
- Bug in hdfstore queries of the form ``where=[('date', '>=', datetime(2013,1,1)), ('date', '<=', datetime(2014,1,1))]`` (:issue:`6313`)

pandas 0.13.1
-------------
Expand Down
17 changes: 12 additions & 5 deletions pandas/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ def __init__(self, where, op=None, value=None, queryables=None,
self.filter = None
self.terms = None
self._visitor = None

# capture the environement if needed
lcls = dict()
if isinstance(where, Expr):
Expand All @@ -497,13 +496,12 @@ def __init__(self, where, op=None, value=None, queryables=None,
where = where.expr

elif isinstance(where, (list, tuple)):

for w in where:
for idx, w in enumerate(where):
if isinstance(w, Expr):
lcls.update(w.env.locals)
else:
w = self.parse_back_compat(w)

where[idx] = w
where = ' & ' .join(["(%s)" % w for w in where])

self.expr = where
Expand All @@ -528,7 +526,16 @@ def parse_back_compat(self, w, op=None, value=None):
warnings.warn("passing a dict to Expr is deprecated, "
"pass the where as a single string",
DeprecationWarning)

if isinstance(w, tuple):
if len(w) == 2:
w, value = w
op = '=='
elif len(w) == 3:
w, op, value = w
warnings.warn("passing a tuple into Expr is deprecated, "
"pass the where as a single string",
DeprecationWarning)

if op is not None:
if not isinstance(w, string_types):
raise TypeError(
Expand Down
44 changes: 44 additions & 0 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,50 @@ def test_term_compat(self):
expected = wp.loc[:,:,['A','B']]
assert_panel_equal(result, expected)

def test_backwards_compat_without_term_object(self):
with ensure_clean_store(self.path) as store:

wp = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
store.append('wp',wp)
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
result = store.select('wp', [('major_axis>20000102'),
('minor_axis', '=', ['A','B']) ])
expected = wp.loc[:,wp.major_axis>Timestamp('20000102'),['A','B']]
assert_panel_equal(result, expected)

store.remove('wp', ('major_axis>20000103'))
result = store.select('wp')
expected = wp.loc[:,wp.major_axis<=Timestamp('20000103'),:]
assert_panel_equal(result, expected)

with ensure_clean_store(self.path) as store:

wp = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
major_axis=date_range('1/1/2000', periods=5),
minor_axis=['A', 'B', 'C', 'D'])
store.append('wp',wp)

# stringified datetimes
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
result = store.select('wp', [('major_axis','>',datetime.datetime(2000,1,2))])
expected = wp.loc[:,wp.major_axis>Timestamp('20000102')]
assert_panel_equal(result, expected)
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
result = store.select('wp', [('major_axis','>',datetime.datetime(2000,1,2,0,0))])
expected = wp.loc[:,wp.major_axis>Timestamp('20000102')]
assert_panel_equal(result, expected)
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
result = store.select('wp', [('major_axis','=',[datetime.datetime(2000,1,2,0,0),
datetime.datetime(2000,1,3,0,0)])])
expected = wp.loc[:,[Timestamp('20000102'),Timestamp('20000103')]]
assert_panel_equal(result, expected)
with tm.assert_produces_warning(expected_warning=DeprecationWarning):
result = store.select('wp', [('minor_axis','=',['A','B'])])
expected = wp.loc[:,:,['A','B']]
assert_panel_equal(result, expected)

def test_same_name_scoping(self):

with ensure_clean_store(self.path) as store:
Expand Down