Skip to content

fix the stack remove error #7335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
change warning to raise error
  • Loading branch information
JunTan committed Nov 1, 2016
commit 9d2d33e729465d8302b1bf723c70ddfc4f1e5b9f
8 changes: 3 additions & 5 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,11 @@ def add(self, key, a):
hash(key)
except TypeError:
raise ValueError("first argument, %s, is not a valid key" % key)

a_existing = dict(self._elements).get(key)
if a_existing is not None:
Stack.remove(self, (key, a_existing))
warnings.warn(
"key %s already existed; Axes is being replaced" % str(key))
# I don't think the above should ever happen.
raise KeyError('Key %s already exists in the AxesStack' % key)
# This only happens if user call this function directly

if a in self:
return None
Expand Down
16 changes: 5 additions & 11 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,17 +232,11 @@ def test_stack_remove():
raise ValueError('Unknown element o')
ValueError: Unknown element o
'''
with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
warnings.simplefilter("always")
# Trigger a warning.
key = '123'
a = figure.AxesStack()
a.add(key, plt.figure().add_subplot(111))
a.add(key, plt.figure().add_subplot(111))
# Verify some things
assert len(w) == 1
assert key in str(w[-1].message)
key = '123'
a = figure.AxesStack()
a.add(key, plt.figure().add_subplot(111))
assert_raises(KeyError, a.add, key, plt.figure().add_subplot(111))
# Verify some things
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is something supposed to come after this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, sorry , it should come before the assertion.



if __name__ == "__main__":
Expand Down