Skip to content

Commit bc6981f

Browse files
authored
Merge pull request #385 from OpenDataServices/ods-empty-column-header
input: Don't fail when an .ods column header is empty
2 parents 69e906b + cac5de7 commit bc6981f

File tree

11 files changed

+71
-10
lines changed

11 files changed

+71
-10
lines changed

.github/workflows/lint.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
restore-keys: |
1919
${{ runner.os }}-pip-
2020
- run: pip install --upgrade -r requirements_dev.txt
21-
- run: pip install black==19.10b0
2221
- run: black --check *.py */
2322
- run: isort --check-only *.py */
2423
- run: flake8

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
runs-on: ubuntu-latest
77
strategy:
88
matrix:
9-
python-version: [ '3.5', '3.6', '3.7', '3.8']
9+
python-version: [ '3.6', '3.7', '3.8']
1010
steps:
1111
- uses: actions/checkout@v2
1212
- name: Setup python

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [0.17.0] - 2021-04-27
10+
11+
### Removed
12+
13+
- We no longer support Python 3.5
14+
15+
### Fixed
16+
17+
- Don't fail when an .ods column header is empty https://github.com/OpenDataServices/flatten-tool/issues/378
18+
919
## [0.16.0] - 2021-03-24
1020

1121
### Fixed

docs/getting-started.rst

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Getting Started
44
Prerequisites
55
-------------
66

7-
You will need Python 3.5 or later, including the venv module.
7+
You will need Python 3.6 or later, including the venv module.
88

99
Generally the venv module should come with your default Python install, but not on Ubuntu. On Ubuntu run:
1010

@@ -41,9 +41,7 @@ will print help information specific to that sub-command.
4141
Python Version Support
4242
----------------------
4343

44-
This code supports Python 3.5 (and later).
44+
This code supports Python 3.6 (and later).
4545

46-
Python 3.4 (and earlier Python 3 versions) is not supported, because one of the dependencies (openpyxl) does not
47-
support it.
48-
49-
Python 2 is not supported because it is now end of life.
46+
Python 3.5 and earlier (including Python 2) are not supported, because they are
47+
end of life, and some of the dependencies do not support them.

flattentool/input.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,10 @@ def get_sheet_lines(self, sheet_name):
882882
output_row = OrderedDict()
883883
for i, x in enumerate(row):
884884

885-
header = coli_to_header[i]
885+
try:
886+
header = coli_to_header[i]
887+
except KeyError:
888+
continue
886889
value = x
887890
if not header:
888891
# None means that the cell will be ignored
8.41 KB
Binary file not shown.
4.68 KB
Binary file not shown.

flattentool/tests/test_input_SpreadsheetInput.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,32 @@ def test_ods_input_formula(self):
312312
OrderedDict([("colC", 4), ("colD", 12)]),
313313
]
314314

315+
def test_xlsx_empty_column_header(self):
316+
xlsxinput = XLSXInput(
317+
input_name="flattentool/tests/fixtures/xlsx/empty_column_header.xlsx"
318+
)
319+
320+
xlsxinput.read_sheets()
321+
322+
assert list(xlsxinput.sub_sheet_names) == ["main"]
323+
assert list(xlsxinput.get_sheet_lines("main")) == [
324+
{"colA": "cell1", None: None},
325+
{"colA": "cell3", None: None},
326+
]
327+
328+
def test_ods_empty_column_header(self):
329+
odsinput = ODSInput(
330+
input_name="flattentool/tests/fixtures/ods/empty_column_header.ods"
331+
)
332+
333+
odsinput.read_sheets()
334+
335+
assert list(odsinput.sub_sheet_names) == ["main"]
336+
assert list(odsinput.get_sheet_lines("main")) == [
337+
{"colA": "cell1"},
338+
{"colA": "cell3"},
339+
]
340+
315341

316342
class TestInputFailure(object):
317343
def test_csv_no_directory(self):

flattentool/tests/test_unflatten.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,27 @@ def test_unflatten_org_xml_xlsx(tmpdir, input_format):
135135
open("flattentool/tests/fixtures/iati-org.xml").read()
136136
== tmpdir.join("output.xml").read()
137137
)
138+
139+
140+
@pytest.mark.parametrize("input_format", ["xlsx", "ods"])
141+
def test_unflatten_empty_column_header(tmpdir, input_format):
142+
unflatten(
143+
input_name="flattentool/tests/fixtures/{}/empty_column_header.{}".format(
144+
input_format, input_format
145+
),
146+
output_name=tmpdir.join("output.json").strpath,
147+
input_format=input_format,
148+
)
149+
assert (
150+
tmpdir.join("output.json").read()
151+
== """{
152+
"main": [
153+
{
154+
"colA": "cell1"
155+
},
156+
{
157+
"colA": "cell3"
158+
}
159+
]
160+
}"""
161+
)

requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ sphinx
88
sphinx_rtd_theme
99
isort
1010
flake8
11+
black==19.10b0
1112
transifex-client

0 commit comments

Comments
 (0)