Skip to content

Commit 5d74fb4

Browse files
committed
Limit the number of empty header row values
Default is 5.
1 parent 5dc164d commit 5d74fb4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/tablib/formats/_ods.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def repeat(cell):
127127
if not row_vals:
128128
continue
129129
if i == skip_lines and headers:
130-
dset.headers = row_vals
130+
dset.headers = limit_row(row_vals)
131131
else:
132132
if i > skip_lines:
133133
if len(row_vals) < dset.width:
@@ -255,3 +255,18 @@ def detect(cls, stream):
255255
return True
256256
except Exception:
257257
return False
258+
259+
260+
def limit_row(headers, limit=5):
261+
"""Limits the number of trailing empty row values"""
262+
limited = []
263+
count = 0
264+
265+
for v in headers:
266+
limited += [v]
267+
count = count + 1 if v == "" else 0
268+
269+
if count == limit:
270+
break
271+
272+
return limited

tests/test_tablib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ def test_ods_import_set_ragged(self):
12601260
ods_source = Path(__file__).parent / 'files' / 'ragged.ods'
12611261
with ods_source.open('rb') as fh:
12621262
dataset = tablib.Dataset().load(fh, 'ods')
1263-
self.assertEqual(dataset[0], (1, '', True) + ('',) * 16381)
1263+
self.assertEqual(dataset[0], (1, '', True) + ('',) * 6)
12641264

12651265
def test_ods_import_columns_repeated(self):
12661266
ods = Path(__file__).parent / "files" / "columns_repeated.ods"

0 commit comments

Comments
 (0)