Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in2csv: iter_rows() got an unexpected keyword argument 'row_offset'

I'm using in2csv from csvkit version 1.0.3, installed using pip with Python 3.7.

When using the tool for the most basic conversion task i.e.

in2csv filename.xlsx > test.csv

I was hit with error

iter_rows() got an unexpected keyword argument 'row_offset'

I understand that the error was reported by the underlying library openpyxl. How can this issue be resolved?

like image 389
idazuwaika Avatar asked Feb 10 '19 15:02

idazuwaika


2 Answers

It seems that row_offset parameter inside iter_rows() has already been deprecated as of openpyxl version 2.6.0 last 6th Feb, 2019. I tried looking at the commit history and saw the following changes: https://bitbucket.org/openpyxl/openpyxl/diff/openpyxl/worksheet/worksheet.py?diff1=e4ec3bde4dcc&diff2=3294de3d5668f462baaa6b0a3c17e3b92b8e5c48&at=default

To fix this, you must no longer use the row_offset and adjust your min_row and max_row accordingly.

e.g.

If you're processing only the 4th row of the worksheet:

# old code
rows = worksheet.iter_rows(row_offset=3, max_row=1)

# new 
rows = worksheet.iter_rows(min_row=4, max_row=4)

If you're processing the rows starting from the 2nd row:

# old 
rows = worksheet.iter_rows(row_offset=1, max_row=(worksheet.max_row - 1)

# new 
rows = worksheet.iter_rows(min_row=2, max_row=worksheet.max_row)

I actually like this change even though it broke my codes. I think using min_row and max_row makes the code more readable and intuitive rather than using the row_offset.

like image 137
alegria Avatar answered Nov 13 '22 03:11

alegria


Just ran into this problem myself, looks to me like a change in openpyxl has broken in2csv.

I've fixed this by uninstalling openpyxl and reinstalling an older version.

pip uninstall openpyxl
pip install openpyxl==2.5 

Or in the case that, like me, you are installing this all from scratch, just install openpyxl 2.5 before installing csv kit

pip install openpyxl==2.5
pip install csvkit
like image 45
OGHaza Avatar answered Nov 13 '22 04:11

OGHaza