BUG: RuntimeError: dictionary changed size during iteration

Hello everyone,

in my program I’m encountering an error when calling the function axes.set_xticks (Matplotlib 1.2.0 on python 2.7-64 bit). It is really difficult for me to build a test case, because my program is really complex. Here is the error traceback:

File “C:\Python27\Lib\site-packages\matplotlib\axes.py”, line 2596, in set_xticks
return self.xaxis.set_ticks(ticks, minor=minor)
File “C:\Python27\Lib\site-packages\matplotlib\axis.py”, line 1489, in set_ticks
self.set_view_interval(min(ticks), max(ticks))
File “C:\Python27\Lib\site-packages\matplotlib\axis.py”, line 1771, in set_view_interval
max(vmin, vmax, Vmax))
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 932, in _set_intervalx
self.invalidate()
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 131, in invalidate
return self._invalidate_internal(value, invalidating_node=self)
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 155, in _invalidate_internal
invalidating_node=self)
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 155, in _invalidate_internal
invalidating_node=self)
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 155, in _invalidate_internal
invalidating_node=self)
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 2141, in _invalidate_internal
invalidating_node=invalidating_node)
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 155, in _invalidate_internal
invalidating_node=self)
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 2141, in _invalidate_internal
invalidating_node=invalidating_node)
File “C:\Python27\Lib\site-packages\matplotlib\transforms.py”, line 153, in _invalidate_internal
for parent in self._parents.itervalues():
File “C:\Python27\Lib\weakref.py”, line 147, in itervalues
for wr in self.data.itervalues():
RuntimeError: dictionary changed size during iteration

I googled and found that this is a well known bug due to the use of self.data.itervalues() in the for loop (i think the correct syntax should be for wr in iter(self.data.items()). So I would like to point out the bug (if it is) to the matplotlib guys, how can I do it?
In the meantime, how can I work around it without changing the source code?
Thanks in advance!

Does this pull request:

https://github.com/matplotlib/matplotlib/pull/1697

fix your issue? I have no way of knowing without a test case...

Mike

···

On 01/22/2013 08:33 AM, Massimiliano Costacurta wrote:

Hello everyone,

in my program I'm encountering an error when calling the function axes.set_xticks (Matplotlib 1.2.0 on python 2.7-64 bit). It is really difficult for me to build a test case, because my program is really complex. Here is the error traceback:

File "C:\Python27\Lib\site-packages\matplotlib\axes.py", line 2596, in set_xticks
  return self.xaxis.set_ticks(ticks, minor=minor)
File "C:\Python27\Lib\site-packages\matplotlib\axis.py", line 1489, in set_ticks
  self.set_view_interval(min(ticks), max(ticks))
File "C:\Python27\Lib\site-packages\matplotlib\axis.py", line 1771, in set_view_interval
  max(vmin, vmax, Vmax))
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 932, in _set_intervalx
  self.invalidate()
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 131, in invalidate
  return self._invalidate_internal(value, invalidating_node=self)
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 155, in _invalidate_internal
  invalidating_node=self)
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 155, in _invalidate_internal
  invalidating_node=self)
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 155, in _invalidate_internal
  invalidating_node=self)
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 2141, in _invalidate_internal
  invalidating_node=invalidating_node)
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 155, in _invalidate_internal
  invalidating_node=self)
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 2141, in _invalidate_internal
  invalidating_node=invalidating_node)
File "C:\Python27\Lib\site-packages\matplotlib\transforms.py", line 153, in _invalidate_internal
  for parent in self._parents.itervalues():
File "C:\Python27\Lib\weakref.py", line 147, in itervalues
  for wr in self.data.itervalues():
RuntimeError: dictionary changed size during iteration

I googled and found that this is a well known bug due to the use of self.data.itervalues() in the for loop (i think the correct syntax should be for wr in iter(self.data.items()). So I would like to point out the bug (if it is) to the matplotlib guys, how can I do it?
In the meantime, how can I work around it without changing the source code?
Thanks in advance!

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnnow-d2d

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users