Skip to content
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 @@ -141,6 +141,7 @@ Bug Fixes
- Bug in hdfstore queries of the form ``where=[('date', '>=', datetime(2013,1,1)), ('date', '<=', datetime(2014,1,1))]`` (:issue:`6313`)
- Bug in DataFrame.dropna with duplicate indices (:issue:`6355`)
- Regression in chained getitem indexing with embedded list-like from 0.12 (:issue:`6394`)
- ``Float64Index`` with nans not comparing correctly

pandas 0.13.1
-------------
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,8 +1950,14 @@ def equals(self, other):
if self is other:
return True

# need to compare nans locations and make sure that they are the same
# since nans don't compare equal this is a bit tricky
try:
return np.array_equal(self, other)
if not isinstance(other, Float64Index):
other = self._constructor(other)
if self.dtype != other.dtype or self.shape != other.shape: return False
left, right = self.values, other.values
return ((left == right) | (isnull(left) & isnull(right))).all()
except TypeError:
# e.g. fails in numpy 1.6 with DatetimeIndex #1681
return False
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,12 @@ class NumericBlock(Block):


class FloatOrComplexBlock(NumericBlock):

def equals(self, other):
if self.dtype != other.dtype or self.shape != other.shape: return False
left, right = self.values, other.values
return ((left == right) | (np.isnan(left) & np.isnan(right))).all()


class FloatBlock(FloatOrComplexBlock):
is_float = True
_downcast_dtype = 'int64'
Expand Down
15 changes: 15 additions & 0 deletions pandas/tests/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,21 @@ def test_astype(self):
self.assert_(i.equals(result))
self.check_is_index(result)

def test_equals(self):

i = Float64Index([1.0,2.0])
self.assertTrue(i.equals(i))
self.assertTrue(i.identical(i))

i2 = Float64Index([1.0,2.0])
self.assertTrue(i.equals(i2))

i = Float64Index([1.0,np.nan])
self.assertTrue(i.equals(i))
self.assertTrue(i.identical(i))

i2 = Float64Index([1.0,np.nan])
self.assertTrue(i.equals(i2))

class TestInt64Index(tm.TestCase):
_multiprocess_can_split_ = True
Expand Down