classification
Title: Timer error pop from empty deque/list
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Randy Henderson, r.david.murray
Priority: normal Keywords:

Created on 2017-08-01 20:50 by Randy Henderson, last changed 2017-08-01 22:25 by Randy Henderson. This issue is now closed.

Messages (3)
msg299634 - (view) Author: Randy Henderson (Randy Henderson) Date: 2017-08-01 20:50
Even when a deque is populated in the Timer setup parameter, the interpreter gives "IndexError: pop from an empty deque".  IndexError is generated for lists as well.

>>> Timer(stmt='d.popleft()',setup='d=deque([1,2,3])',globals=globals()).timeit()
Traceback (most recent call last):
  File "<pyshell#75>", line 1, in <module>
 Timer(stmt='d.popleft()',setup='d=deque([1,2,3])',globals=globals()).timeit()
  File "C:\Program Files\Python\Python36\lib\timeit.py", line 178, in timeit
    timing = self.inner(it, self.timer)
  File "<timeit-src>", line 6, in inner
IndexError: pop from an empty deque
msg299636 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-08-01 20:58
Perhaps I'm missing something, but isn't this to be expected?  Timer will run d.popleft() repeatedly until you get the error you see because the list is empty.  Are you thinking that setup is run each time?  That would defeat its purpose.
msg299638 - (view) Author: Randy Henderson (Randy Henderson) Date: 2017-08-01 22:21
You're right.  I was expecting the code in stmt to be run only once, but I
just discovered in the documentation that the default is for it to be run
one million times.  I provided the argument 'number=1' to the timeit()
method and am now getting the behavior I expected.  I'll remove/close the
bug entry.  Sorry -- newbie!

On Tue, Aug 1, 2017 at 1:58 PM, R. David Murray <report@bugs.python.org>
wrote:

>
> R. David Murray added the comment:
>
> Perhaps I'm missing something, but isn't this to be expected?  Timer will
> run d.popleft() repeatedly until you get the error you see because the list
> is empty.  Are you thinking that setup is run each time?  That would defeat
> its purpose.
>
> ----------
> nosy: +r.david.murray
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue31099>
> _______________________________________
>
History
Date User Action Args
2017-08-01 22:25:49Randy Hendersonsetstatus: open -> closed
resolution: not a bug
stage: resolved
2017-08-01 22:21:55Randy Hendersonsetmessages: + msg299638
2017-08-01 20:58:34r.david.murraysetnosy: + r.david.murray
messages: + msg299636
2017-08-01 20:50:29Randy Hendersoncreate