Skip to content

Commit 35fcc17

Browse files
committed
BUG: closes #780, compare float to within 32bit precision
1 parent a0186ea commit 35fcc17

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pandas/core/indexing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,13 @@ def _get_slice_axis(self, slice_obj, axis=0):
315315

316316
return self._slice(slicer, axis=axis)
317317

318+
# 32-bit floating point machine epsilon
319+
_eps = np.finfo('f4').eps
318320

319321
def _is_index_slice(obj):
320322
def _is_valid_index(x):
321-
return com.is_integer(x) or com.is_float(x) and np.allclose(x, int(x))
323+
return (com.is_integer(x) or com.is_float(x)
324+
and np.allclose(x, int(x), rtol=_eps, atol=0))
322325

323326
def _crit(v):
324327
return v is None or _is_valid_index(v)

pandas/tests/test_frame.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,19 @@ def test_getitem_fancy_2d(self):
395395
exp.values[5:10] = 5
396396
assert_frame_equal(f, exp)
397397

398+
def test_slice_floats(self):
399+
index = [52195.504153, 52196.303147, 52198.369883]
400+
df = DataFrame(np.random.rand(3, 2), index=index)
401+
402+
s1 = df.ix[52195.1:52196.5]
403+
self.assertEquals(len(s1), 2)
404+
405+
s1 = df.ix[52195.1:52196.6]
406+
self.assertEquals(len(s1), 2)
407+
408+
s1 = df.ix[52195.1:52198.9]
409+
self.assertEquals(len(s1), 3)
410+
398411
def test_getitem_fancy_slice_integers_step(self):
399412
df = DataFrame(np.random.randn(10, 5))
400413

0 commit comments

Comments
 (0)