Added FrozenList subtraction · mcocdawc/pandas@ada7cda (original) (raw)
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -28,8 +28,13 @@ def __add__(self, other): | ||
28 | 28 | if isinstance(other, tuple): |
29 | 29 | other = list(other) |
30 | 30 | return self.__class__(super(FrozenList, self).__add__(other)) |
31 | - | |
31 | + | |
32 | 32 | __iadd__ = __add__ |
33 | + | |
34 | +def __sub__(self, other): | |
35 | +other = set(other) | |
36 | +temp = [x for x in self if x not in other] | |
37 | +return self.__class__(temp) | |
33 | 38 | |
34 | 39 | # Python 2 compat |
35 | 40 | def __getslice__(self, i, j): |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -22,7 +22,17 @@ def test_add(self): | ||
22 | 22 | result = (1, 2, 3) + self.container |
23 | 23 | expected = FrozenList([1, 2, 3] + self.lst) |
24 | 24 | self.check_result(result, expected) |
25 | - | |
25 | + | |
26 | +def test_sub(self): | |
27 | +result = self.container - [2] | |
28 | +expected = FrozenList([1, 3, 4, 5]) | |
29 | +self.check_result(result, expected) | |
30 | + | |
31 | +def test_sub_dupe(self): | |
32 | +result = FrozenList([1, 2, 3, 2]) - [2] | |
33 | +expected = FrozenList([1, 3]) | |
34 | +self.check_result(result, expected) | |
35 | + | |
26 | 36 | def test_inplace(self): |
27 | 37 | q = r = self.container |
28 | 38 | q += [5] |