-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: syntax error in hdf query with ts #15544
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -188,10 +188,6 @@ def stringify(value): | |
if v.tz is not None: | ||
v = v.tz_convert('UTC') | ||
return TermValue(v, v.value, kind) | ||
elif (isinstance(v, datetime) or hasattr(v, 'timetuple') or | ||
kind == u('date')): | ||
v = time.mktime(v.timetuple()) | ||
return TermValue(v, pd.Timestamp(v), kind) | ||
elif kind == u('timedelta64') or kind == u('timedelta'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jreback - any idea what this was supposed to be doing? This doesn't impact any tested behavior and not sure it ever would have worked. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was some really old compat IIRC. (or maybe just copied it from somewhere :>) improving test coverage by deletions! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah that isn't hit at all in the tests There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is another reference to |
||
v = _coerce_scalar_to_timedelta_type(v, unit='s').value | ||
return TermValue(int(v), v, kind) | ||
|
@@ -218,12 +214,13 @@ def stringify(value): | |
else: | ||
v = bool(v) | ||
return TermValue(v, v, kind) | ||
elif not isinstance(v, string_types): | ||
v = stringify(v) | ||
elif isinstance(v, string_types): | ||
# string quoting | ||
return TermValue(v, stringify(v), u('string')) | ||
|
||
# string quoting | ||
return TermValue(v, stringify(v), u('string')) | ||
else: | ||
raise TypeError(("Cannot compare {v} of type {typ}" | ||
" to {kind} column").format(v=v, typ=type(v), | ||
kind=kind)) | ||
|
||
def convert_values(self): | ||
pass | ||
|
@@ -558,9 +555,8 @@ def parse_back_compat(self, w, op=None, value=None): | |
|
||
# stringify with quotes these values | ||
def convert(v): | ||
if (isinstance(v, (datetime, np.datetime64, | ||
timedelta, np.timedelta64)) or | ||
hasattr(v, 'timetuple')): | ||
if isinstance(v, (datetime, np.datetime64, | ||
timedelta, np.timedelta64)): | ||
return "'{0}'".format(v) | ||
return v | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5080,6 +5080,27 @@ def test_query_long_float_literal(self): | |
expected = df.loc[[1], :] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
def test_query_compare_string_column(self): | ||
# GH 15492 | ||
df = pd.DataFrame({'date': ['2014-01-01', '2014-01-02'], | ||
'real_date': date_range('2014-01-01', periods=2), | ||
'values': [1, 2]}, | ||
columns=['date', 'real_date', 'values']) | ||
|
||
with ensure_clean_store(self.path) as store: | ||
store.append('test', df, format='table', data_columns=True) | ||
|
||
ts = pd.Timestamp('2014-01-01') # noqa | ||
result = store.select('test', where='real_date > ts') | ||
expected = df.loc[[1], :] | ||
tm.assert_frame_equal(expected, result) | ||
|
||
for v in [2.1, True, pd.Timestamp('2014-01-01')]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also test int/float vs strings column (might work though.....) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, convertible strings will work, added some more test cases |
||
for op in ['<', '>', '==']: | ||
query = 'date {op} v'.format(op=op) | ||
with tm.assertRaises(TypeError): | ||
result = store.select('test', where=query) | ||
|
||
|
||
class TestHDFComplexValues(Base): | ||
# GH10447 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of putting the try/except. Just show the actual traceback (well just the exception part), e.g.
I would show like this
for a code block I literally execute the code and copy-paste (as it is not executed), just formatted.