We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents e2f0b56 + b7194ab commit 5a3076aCopy full SHA for 5a3076a
doc/source/release.rst
@@ -169,6 +169,7 @@ Bug Fixes
169
- Bug in :meth:`DataFrame.replace` where nested dicts were erroneously
170
depending on the order of dictionary keys and values (:issue:`5338`).
171
- Perf issue in concatting with empty objects (:issue:`3259`)
172
+- Clarify sorting of ``sym_diff`` on ``Index``es with ``NaN``s (:isssue:`6444`)
173
174
pandas 0.13.1
175
-------------
pandas/core/index.py
@@ -1045,6 +1045,9 @@ def sym_diff(self, other, result_name=None):
1045
``idx2`` but not both. Equivalent to the Index created by
1046
``(idx1 - idx2) + (idx2 - idx1)`` with duplicates dropped.
1047
1048
+ The sorting of a result containing ``NaN``s is not guaranteed
1049
+ across Python versions. See GitHub issue #6444.
1050
+
1051
Examples
1052
--------
1053
>>> idx1 = Index([1, 2, 3, 4])
@@ -1067,7 +1070,6 @@ def sym_diff(self, other, result_name=None):
1067
1070
the_diff = sorted(set((self - other) + (other - self)))
1068
1071
return Index(the_diff, name=result_name)
1069
1072
-
1073
def unique(self):
1074
"""
1075
Return array of unique values in the Index. Significantly faster than
pandas/tests/test_index.py
@@ -493,13 +493,16 @@ def test_symmetric_diff(self):
493
self.assert_(tm.equalContents(result, expected))
494
495
# nans:
496
- idx1 = Index([1, 2, np.nan])
+ # GH #6444, sorting of nans. Make sure the number of nans is right
497
+ # and the correct non-nan values are there. punt on sorting.
498
+ idx1 = Index([1, 2, 3, np.nan])
499
idx2 = Index([0, 1, np.nan])
500
result = idx1.sym_diff(idx2)
- expected = Index([0.0, np.nan, 2.0, np.nan]) # oddness with nans
- nans = pd.isnull(expected)
501
- self.assert_(pd.isnull(result[nans]).all())
502
- self.assert_(tm.equalContents(result[~nans], expected[~nans]))
+ # expected = Index([0.0, np.nan, 2.0, 3.0, np.nan])
+ nans = pd.isnull(result)
503
+ self.assertEqual(nans.sum(), 2)
504
+ self.assertEqual((~nans).sum(), 3)
505
+ [self.assertIn(x, result) for x in [0.0, 2.0, 3.0]]
506
507
# other not an Index:
508
idx1 = Index([1, 2, 3, 4], name='idx1')
0 commit comments