Exemplo n.º 1
0
    def test_symmetric_difference_non_index(self, sort):
        index1 = Index([1, 2, 3, 4], name="index1")
        index2 = np.array([2, 3, 4, 5])
        expected = Index([1, 5])
        result = index1.symmetric_difference(index2, sort=sort)
        assert tm.equalContents(result, expected)
        assert result.name == "index1"

        result = index1.symmetric_difference(index2, result_name="new_name", sort=sort)
        assert tm.equalContents(result, expected)
        assert result.name == "new_name"
Exemplo n.º 2
0
    def test_reversed_xor_with_index_returns_index(self):
        # GH#22092, GH#19792
        ser = Series([True, True, False, False])
        idx1 = Index([True, False, True, False])
        idx2 = Index([1, 0, 1, 0])

        expected = Index.symmetric_difference(idx1, ser)
        result = idx1 ^ ser
        assert_index_equal(result, expected)

        expected = Index.symmetric_difference(idx2, ser)
        result = idx2 ^ ser
        assert_index_equal(result, expected)
Exemplo n.º 3
0
    def test_reversed_logical_ops_with_index(self, op):
        # GH#22092, GH#19792
        ser = Series([True, True, False, False])
        idx1 = Index([True, False, True, False])
        idx2 = Index([1, 0, 1, 0])

        # symmetric_difference is only for rxor, but other 2 should fail
        expected = idx1.symmetric_difference(ser)

        result = op(ser, idx1)
        assert_index_equal(result, expected)

        expected = idx2.symmetric_difference(ser)

        result = op(ser, idx2)
        assert_index_equal(result, expected)
Exemplo n.º 4
0
    def test_reversed_logical_ops_with_index(self, op):
        # GH#22092, GH#19792
        ser = Series([True, True, False, False])
        idx1 = Index([True, False, True, False])
        idx2 = Index([1, 0, 1, 0])

        # symmetric_difference is only for rxor, but other 2 should fail
        expected = idx1.symmetric_difference(ser)

        result = op(ser, idx1)
        assert_index_equal(result, expected)

        expected = idx2.symmetric_difference(ser)

        result = op(ser, idx2)
        assert_index_equal(result, expected)
    def test_reversed_xor_with_index_returns_index(self):
        # GH#22092, GH#19792
        ser = Series([True, True, False, False])
        idx1 = Index([True, False, True, False])
        idx2 = Index([1, 0, 1, 0])

        msg = "operating as a set operation"

        expected = Index.symmetric_difference(idx1, ser)
        with tm.assert_produces_warning(FutureWarning, match=msg):
            result = idx1 ^ ser
        tm.assert_index_equal(result, expected)

        expected = Index.symmetric_difference(idx2, ser)
        with tm.assert_produces_warning(FutureWarning, match=msg):
            result = idx2 ^ ser
        tm.assert_index_equal(result, expected)
Exemplo n.º 6
0
    def test_symmetric_difference_missing(self, index2, expected, sort):
        # GH#13514 change: {nan} - {nan} == {}
        # (GH#6444, sorting of nans, is no longer an issue)
        index1 = Index([1, np.nan, 2, 3])

        result = index1.symmetric_difference(index2, sort=sort)
        if sort is None:
            expected = expected.sort_values()
        tm.assert_index_equal(result, expected)
Exemplo n.º 7
0
    def test_symmetric_difference(self, sort):
        # smoke
        index1 = Index([5, 2, 3, 4], name="index1")
        index2 = Index([2, 3, 4, 1])
        result = index1.symmetric_difference(index2, sort=sort)
        expected = Index([5, 1])
        assert tm.equalContents(result, expected)
        assert result.name is None
        if sort is None:
            expected = expected.sort_values()
        tm.assert_index_equal(result, expected)

        # __xor__ syntax
        with tm.assert_produces_warning(FutureWarning):
            expected = index1 ^ index2
        assert tm.equalContents(result, expected)
        assert result.name is None
Exemplo n.º 8
0
def _symmetric_difference(left: pd.Index, right: pd.Index) -> pd.Index:
    return left.symmetric_difference(right, sort=False)