8000 Merge pull request #2597 from tacaswell/add_SubplotSpec__eq__ · matplotlib/matplotlib@3284b17 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3284b17

Browse files
committed
Merge pull request #2597 from tacaswell/add_SubplotSpec__eq__
BUG: Add subplot spec eq
2 parents f968f14 + 071bd89 commit 3284b17

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@ def tk_window_focus():
12451245
'matplotlib.tests.test_dates',
12461246
'matplotlib.tests.test_delaunay',
12471247
'matplotlib.tests.test_figure',
1248+
'matplotlib.tests.test_gridspec',
12481249
'matplotlib.tests.test_image',
12491250
'matplotlib.tests.test_legend',
12501251
'matplotlib.tests.test_lines',

lib/matplotlib/gridspec.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,19 @@ def get_topmost_subplotspec(self):
457457
return gridspec.get_topmost_subplotspec()
458458
else:
459459
return self
460+
461+
def __eq__(self, other):
462+
# check to make sure other has the attributes
463+
# we need to do the comparison
464+
if not (hasattr(other, '_gridspec') and
465+
hasattr(other, 'num1') and
466+
hasattr(other, 'num2')):
467+
return False
468+
return all((self._gridspec == other._gridspec,
469+
self.num1 == other.num1,
470+
self.num2 == other.num2))
471+
472+
def __hash__(self):
473+
return (hash(self._gridspec) ^
474+
hash(self.num1) ^
475+
hash(self.num2))

lib/matplotlib/tests/test_gridspec.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import matplotlib.gridspec as gridspec
2+
from nose.tools import assert_equal
3+
4+
5+
def test_equal():
6+
gs = gridspec.GridSpec(2, 1)
7+
assert_equal(gs[0, 0], gs[0, 0])
8+
assert_equal(gs[:, 0], gs[:, 0])

0 commit comments

Comments
 (0)
0