Skip to content

Commit

Permalink
fix: Fix error on unsized sheets in XLSX files wireservice/csvkit#1221
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmckinney committed Nov 20, 2023
1 parent fb24ccb commit aa611c3
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.4.1 - November 20, 2023
-------------------------

* fix: :meth:`.Table.from_xlsx` no longer errors on unsized sheets.

0.4.0 - November 7, 2023
------------------------

Expand Down
5 changes: 4 additions & 1 deletion agateexcel/table_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def from_xlsx(cls, path, sheet=None, skip_lines=0, header=True, read_only=True,
offset = 0
rows = []

if read_only and (reset_dimensions or reset_dimensions is None and sheet.calculate_dimension() == 'A1:A1'):
if (
read_only
and (reset_dimensions or (reset_dimensions is None and sheet.max_column == 1 and sheet.max_row == 1))
):
try:
sheet.reset_dimensions()
sheet.calculate_dimension(force=True)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

project = 'agate-excel'
copyright = '2017, Christopher Groskopf'
version = '0.4.0'
version = '0.4.1'
release = version

# -- General configuration ---------------------------------------------------
Expand Down
Binary file added examples/covid_19-iss.xlsx
Binary file not shown.
Binary file added examples/ne_1033_data.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='agate-excel',
version='0.4.0',
version='0.4.1',
description='agate-excel adds read support for Excel files (xls and xlsx) to agate.',
long_description=long_description,
long_description_content_type='text/x-rst',
Expand Down
13 changes: 13 additions & 0 deletions tests/test_table_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,16 @@ def test_row_limit_too_high(self):
self.assertColumnNames(table, self.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_unsized(self):
table = agate.Table.from_xlsx('examples/ne_1033_data.xlsx')

self.assertEqual(len(table.columns), 14)
self.assertEqual(len(table.rows), 1036)

def test_from_xlsx_size_1(self):
# https://github.com/wireservice/csvkit/issues/1129
table = agate.Table.from_xlsx('examples/covid_19-iss.xlsx')

self.assertEqual(len(table.columns), 18)
self.assertEqual(len(table.rows), 46)

0 comments on commit aa611c3

Please sign in to comment.