Skip to content

Commit 841973d

Browse files
sarathfrancis90juarezr
authored andcommitted
Fix filldown RuntimeError on header-only tables
filldown eagerly reads the first data row to seed its fill values, so a table with a header but no data rows raised "RuntimeError: generator raised StopIteration" (the StopIteration from next() escaping the generator under PEP 479). fillright and fillleft already handle that input by returning the header unchanged; guard the seed read so filldown behaves the same.
1 parent 97fbbfd commit 841973d

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

petl/test/transform/test_fills.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ def test_filldown_headerless():
6060
ieq(expect, actual)
6161

6262

63+
def test_filldown_header_only():
64+
table = (('foo', 'bar', 'baz'),)
65+
expect = (('foo', 'bar', 'baz'),)
66+
67+
actual = filldown(table)
68+
ieq(expect, actual)
69+
ieq(expect, actual)
70+
71+
actual = filldown(table, 'bar')
72+
ieq(expect, actual)
73+
ieq(expect, actual)
74+
75+
6376
def test_fillright():
6477

6578
table = (('foo', 'bar', 'baz'),

petl/transform/fills.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ def iterfilldown(table, fillfields, missing):
112112
if not fillfields: # fill down all fields
113113
fillfields = hdr
114114
fillindices = asindices(hdr, fillfields)
115-
fill = list(next(it)) # fill values
115+
try:
116+
fill = list(next(it)) # fill values
117+
except StopIteration:
118+
return
116119
yield tuple(fill)
117120
for row in it:
118121
outrow = list(row)

0 commit comments

Comments
 (0)