Repository: wireservice/agate-excel

Issue:
Passing column_names to from_xls fails with TypeError
```
Traceback (most recent call last):
  File "<stdin>", line 5, in <module>
  File "/Users/jani.mikkonen/src/customers/vr/vr/venv/lib/python3.7/site-packages/agateexcel/table_xls.py", line 86, in from_xls
    tables[sheet.name] = agate.Table(rows, column_names, **kwargs)
TypeError: __init__() got multiple values for argument 'column_names'
```

if column_names is present in kwargs, maybe remove column_names  from  there and copy it to the positional parameter passed to agate.Table() in https://github.com/wireservice/agate-excel/blob/master/agateexcel/table_xlsx.py#L85 & https://github.com/wireservice/agate-excel/blob/master/agateexcel/table_xls.py#L86  ? 





Discussion:

Patch:
diff --git a/agateexcel/table_xls.py b/agateexcel/table_xls.py
index 19612c6..9fb9c4a 100644
--- a/agateexcel/table_xls.py
+++ b/agateexcel/table_xls.py
@@ -83,6 +83,11 @@ def from_xls(cls, path, sheet=None, skip_lines=0, header=True, encoding_override
             for i in range(len(columns[0])):
                 rows.append([c[i] for c in columns])
 
+        if 'column_names' in kwargs:
+            if not header:
+                column_names = kwargs.get('column_names', None)
+            del kwargs['column_names']
+
         tables[sheet.name] = agate.Table(rows, column_names, **kwargs)
 
     if multiple:
diff --git a/agateexcel/table_xlsx.py b/agateexcel/table_xlsx.py
index 87619e9..37afd71 100644
--- a/agateexcel/table_xlsx.py
+++ b/agateexcel/table_xlsx.py
@@ -82,6 +82,11 @@ def from_xlsx(cls, path, sheet=None, skip_lines=0, header=True, read_only=True,
 
             rows.append(values)
 
+        if 'column_names' in kwargs:
+            if not header:
+                column_names = kwargs.get('column_names', None)
+            del kwargs['column_names']
+
         tables[sheet.title] = agate.Table(rows, column_names, **kwargs)
 
     f.close()


Test patch:
diff --git a/tests/test_table_xls.py b/tests/test_table_xls.py
index cc7b3e8..6d02d74 100644
--- a/tests/test_table_xls.py
+++ b/tests/test_table_xls.py
@@ -19,6 +19,10 @@ class TestXLS(agate.AgateTestCase):
             'number', 'text', 'boolean', 'date', 'datetime',
         ]
 
+        self.user_provided_column_names = [
+            'alt number', 'alt text', 'alt boolean', 'alt date', 'alt datetime',
+        ]
+
         self.column_types = [
             agate.Number(), agate.Text(), agate.Boolean(),
             agate.Date(), agate.DateTime(),
@@ -26,6 +30,13 @@ class TestXLS(agate.AgateTestCase):
 
         self.table = agate.Table(self.rows, self.column_names, self.column_types)
 
+    def test_from_xls_with_column_names(self):
+        table = agate.Table.from_xls('examples/test.xls', header=False, skip_lines=1, column_names=self.user_provided_column_names )
+
+        self.assertColumnNames(table, self.user_provided_column_names)
+        self.assertColumnTypes(table, [agate.Number, agate.Text, agate.Boolean, agate.Date, agate.DateTime])
+        self.assertRows(table, [r.values() for r in self.table.rows])
+
     def test_from_xls(self):
         table = agate.Table.from_xls('examples/test.xls')
 
diff --git a/tests/test_table_xlsx.py b/tests/test_table_xlsx.py
index 6dd4434..9b56b9b 100644
--- a/tests/test_table_xlsx.py
+++ b/tests/test_table_xlsx.py
@@ -19,6 +19,10 @@ class TestXLSX(agate.AgateTestCase):
             'number', 'text', 'boolean', 'date', 'datetime',
         ]
 
+        self.user_provided_column_names = [
+            'number', 'text', 'boolean', 'date', 'datetime',
+        ]
+
         self.column_types = [
             agate.Number(), agate.Text(), agate.Boolean(),
             agate.Date(), agate.DateTime(),
@@ -26,6 +30,13 @@ class TestXLSX(agate.AgateTestCase):
 
         self.table = agate.Table(self.rows, self.column_names, self.column_types)
 
+    def test_from_xlsx_with_column_names(self):
+        table = agate.Table.from_xlsx('examples/test.xlsx', header=False, skip_lines=1, column_names=self.user_provided_column_names)
+
+        self.assertColumnNames(table, self.user_provided_column_names)
+        self.assertColumnTypes(table, [agate.Number, agate.Text, agate.Boolean, agate.Date, agate.DateTime])
+        self.assertRows(table, [r.values() for r in self.table.rows])
+
     def test_from_xlsx(self):
         table = agate.Table.from_xlsx('examples/test.xlsx')