Skip to content

Commit

Permalink
Fix iterrowslice to conform with Python 3.7 PEP 479 which transforms …
Browse files Browse the repository at this point in the history
…StopIteration in generators to RuntimeError exceptions
  • Loading branch information
arturponinski committed Feb 8, 2022
1 parent ea33e5c commit 96cdc78
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docs/changes.rst
Expand Up @@ -4,6 +4,9 @@ Changes
Version 1.7.8
-------------

* Fix iterrowslice() to conform with PEP 479
By :user:`arturponinski`, :issue:`575`.

* Cleanup and unclutter old and unused files in repository
By :user:`juarezr`, :issue:`606`.

Expand Down
15 changes: 15 additions & 0 deletions petl/test/transform/test_basics.py
@@ -1,5 +1,6 @@
from __future__ import absolute_import, print_function, division

import pytest

from petl.test.helpers import ieq
from petl.util import expr, empty, coalesce
Expand Down Expand Up @@ -460,6 +461,20 @@ def test_head():
ieq(expect, table2)


def test_head_raises_stop_iteration_for_empty_table():
table = iter(head([]))
with pytest.raises(StopIteration):
next(table) # header


def test_head_raises_stop_iteration_for_header_only():
table1 = (('foo', 'bar', 'baz'),)
table = iter(head(table1))
next(table) # header
with pytest.raises(StopIteration):
next(table)


def test_tail():

table1 = (('foo', 'bar'),
Expand Down
5 changes: 4 additions & 1 deletion petl/transform/basics.py
Expand Up @@ -727,7 +727,10 @@ def __iter__(self):

def iterrowslice(source, sliceargs):
it = iter(source)
yield tuple(next(it)) # fields
try:
yield tuple(next(it)) # fields
except StopIteration:
return
for row in islice(it, *sliceargs):
yield tuple(row)

Expand Down

0 comments on commit 96cdc78

Please sign in to comment.