Skip to content

Commit 73564ab

Browse files
committed
Added FrozenList subtraction
1 parent d0a281f commit 73564ab

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

pandas/indexes/frozen.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,13 @@ def __add__(self, other):
2828
if isinstance(other, tuple):
2929
other = list(other)
3030
return self.__class__(super(FrozenList, self).__add__(other))
31-
31+
3232
__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)
3338

3439
# Python 2 compat
3540
def __getslice__(self, i, j):

pandas/tests/indexes/test_frozen.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,17 @@ def test_add(self):
2222
result = (1, 2, 3) + self.container
2323
expected = FrozenList([1, 2, 3] + self.lst)
2424
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+
2636
def test_inplace(self):
2737
q = r = self.container
2838
q += [5]

0 commit comments

Comments
 (0)