Skip to content

Commit

Permalink
Added FrozenList subtraction
Browse files Browse the repository at this point in the history
  • Loading branch information
benthayer committed Mar 1, 2017
1 parent d0a281f commit 73564ab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pandas/indexes/frozen.py
Expand Up @@ -28,8 +28,13 @@ def __add__(self, other):
if isinstance(other, tuple):
other = list(other)
return self.__class__(super(FrozenList, self).__add__(other))

__iadd__ = __add__

def __sub__(self, other):
other = set(other)
temp = [x for x in self if x not in other]
return self.__class__(temp)

# Python 2 compat
def __getslice__(self, i, j):
Expand Down
12 changes: 11 additions & 1 deletion pandas/tests/indexes/test_frozen.py
Expand Up @@ -22,7 +22,17 @@ def test_add(self):
result = (1, 2, 3) + self.container
expected = FrozenList([1, 2, 3] + self.lst)
self.check_result(result, expected)


def test_sub(self):
result = self.container - [2]
expected = FrozenList([1, 3, 4, 5])
self.check_result(result, expected)

def test_sub_dupe(self):
result = FrozenList([1, 2, 3, 2]) - [2]
expected = FrozenList([1, 3])
self.check_result(result, expected)

def test_inplace(self):
q = r = self.container
q += [5]
Expand Down

0 comments on commit 73564ab

Please sign in to comment.