Skip to content

Commit

Permalink
Fix convertall() when header line contain non-string values
Browse files Browse the repository at this point in the history
Fixes #579.
  • Loading branch information
dnicolodi committed Jan 14, 2022
1 parent 012cc7f commit 682d26e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions petl/test/transform/test_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ def test_convertall():
ieq(expect2, table2)
ieq(expect2, table2)

# test with non-string field names
table1 = (('foo', 3, 4),
(2, 2, 2))
table2 = convertall(table1, lambda x: x**2)
expect = (('foo', 3, 4),
(4, 4, 4))
ieq(expect, table2)


def test_convertnumbers():

Expand Down
4 changes: 2 additions & 2 deletions petl/transform/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import petl.config as config
from petl.errors import ArgumentError, FieldSelectionError
from petl.util.base import Table, expr, header, Record
from petl.util.base import Table, expr, fieldnames, Record
from petl.util.parsers import numparser


Expand Down Expand Up @@ -242,7 +242,7 @@ def convertall(table, *args, **kwargs):
"""

# TODO don't read the data twice!
return convert(table, header(table), *args, **kwargs)
return convert(table, fieldnames(table), *args, **kwargs)


Table.convertall = convertall
Expand Down

0 comments on commit 682d26e

Please sign in to comment.