Skip to content

Commit 05de4ae

Browse files
committed
fix rounding in pytables query
1 parent b386184 commit 05de4ae

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

doc/source/whatsnew/v0.19.0.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ Bug Fixes
15671567
- Bug in ``DataFrame.to_csv()`` with ``MultiIndex`` columns in which a stray empty line was added (:issue:`6618`)
15681568
- Bug in ``DatetimeIndex``, ``TimedeltaIndex`` and ``PeriodIndex.equals()`` may return ``True`` when input isn't ``Index`` but contains the same values (:issue:`13107`)
15691569
- Bug in assignment against datetime with timezone may not work if it contains datetime near DST boundary (:issue:`14146`)
1570-
- Bug in ``pd.eval()`` truncating long float literals with python 2 (:issue:`14241`)
1570+
- Bug in ``pd.eval()`` and ``HDFStore`` query truncating long float literals with python 2 (:issue:`14241`)
15711571
- Bug in ``Index`` raises ``KeyError`` displaying incorrect column when column is not in the df and columns contains duplicate values (:issue:`13822`)
15721572
- Bug in ``Period`` and ``PeriodIndex`` creating wrong dates when frequency has combined offset aliases (:issue:`13874`)
15731573
- Bug in ``.to_string()`` when called with an integer ``line_width`` and ``index=False`` raises an UnboundLocalError exception because ``idx`` referenced before assignment.

pandas/computation/pytables.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,14 @@ def __init__(self, value, converted, kind):
611611
def tostring(self, encoding):
612612
""" quote the string if not encoded
613613
else encode and return """
614-
if self.kind == u('string'):
614+
if self.kind == u'string':
615615
if encoding is not None:
616616
return self.converted
617617
return '"%s"' % self.converted
618+
elif self.kind == u'float':
619+
# python 2 str(float) is not always
620+
# round-trippable so use repr()
621+
return repr(self.converted)
618622
return self.converted
619623

620624

pandas/io/tests/test_pytables.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5003,6 +5003,16 @@ def test_read_from_py_localpath(self):
50035003
tm.assert_frame_equal(expected, actual)
50045004

50055005

5006+
def test_query_long_float_literal(self):
5007+
# GH 14241
5008+
df = pd.DataFrame([{"A": 1000000000.0099}])
5009+
cutoff = 1000000000.006
5010+
with ensure_clean_store(self.path) as store:
5011+
store.append('test', df, format='table', data_columns=True)
5012+
result = store.select('test', "A < %.3f" % cutoff)
5013+
self.assertTrue(result.empty)
5014+
5015+
50065016
class TestHDFComplexValues(Base):
50075017
# GH10447
50085018

0 commit comments

Comments
 (0)