Skip to content

COMPAT: back compat for HDFStore with a Term #5794

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 1 commit into from
Dec 30, 2013
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
16 changes: 14 additions & 2 deletions pandas/computation/pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import time
import warnings
from functools import partial
from datetime import datetime

from datetime import datetime, timedelta
import numpy as np
import pandas as pd
from pandas.compat import u, string_types, PY3
from pandas.core.base import StringMixin
Expand Down Expand Up @@ -540,6 +540,18 @@ def parse_back_compat(self, w, op=None, value=None):
if value is not None:
if isinstance(value, Expr):
raise TypeError("invalid value passed, must be a string")

# stringify with quotes these values
def convert(v):
if isinstance(v, (datetime,np.datetime64,timedelta,np.timedelta64)) or hasattr(v, 'timetuple'):
return "'{0}'".format(v)
return v

if isinstance(value, (list,tuple)):
value = [ convert(v) for v in value ]
else:
value = convert(value)

w = "{0}{1}".format(w, value)

warnings.warn("passing multiple values to Expr is deprecated, "
Expand Down
24 changes: 24 additions & 0 deletions pandas/io/tests/test_pytables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,30 @@ def test_term_compat(self):
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
result = store.select('wp', [Term('major_axis','>',datetime.datetime(2000,1,2))])
expected = wp.loc[:,wp.major_axis>Timestamp('20000102')]
assert_panel_equal(result, expected)

result = store.select('wp', [Term('major_axis','>',datetime.datetime(2000,1,2,0,0))])
expected = wp.loc[:,wp.major_axis>Timestamp('20000102')]
assert_panel_equal(result, expected)

result = store.select('wp', [Term('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)

result = store.select('wp', [Term('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