Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2dfb60b

Browse filesBrowse files
committed
ENH: add remove method to cbook.Grouper
- also add tests
1 parent 162e25b commit 2dfb60b
Copy full SHA for 2dfb60b

File tree

Expand file treeCollapse file tree

2 files changed

+29
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+29
-0
lines changed

‎lib/matplotlib/cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook.py
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,14 @@ def joined(self, a, b):
17211721
except KeyError:
17221722
return False
17231723

1724+
def remove(self, a):
1725+
self.clean()
1726+
1727+
mapping = self._mapping
1728+
seta = mapping.pop(ref(a), None)
1729+
if seta is not None:
1730+
seta.remove(ref(a))
1731+
17241732
def __iter__(self):
17251733
"""
17261734
Iterate over each of the disjoint sets as a list.

‎lib/matplotlib/tests/test_cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_cbook.py
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import (absolute_import, division, print_function,
22
unicode_literals)
3+
import itertools
34

45
from matplotlib.externals import six
56

@@ -376,3 +377,23 @@ def test_step_fails():
376377
np.arange(12))
377378
assert_raises(ValueError, cbook._step_validation,
378379
np.arange(12), np.arange(3))
380+
381+
382+
def test_grouper():
383+
class dummy():
384+
pass
385+
a, b, c, d, e = objs = [dummy() for j in range(5)]
386+
g = cbook.Grouper()
387+
g.join(*objs)
388+
assert set(list(g)[0]) == set(objs)
389+
assert set(g.get_siblings(a)) == set(objs)
390+
391+
for other in objs[1:]:
392+
assert g.joined(a, other)
393+
394+
g.remove(a)
395+
for other in objs[1:]:
396+
assert not g.joined(a, other)
397+
398+
for A, B in itertools.product(objs[1:], objs[1:]):
399+
assert g.joined(A, B)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.