Skip to content

Commit 0927d6d

Browse files
authored
Merge pull request #361 from OpenDataServices/306-fix-titles-keyerror
flatten: Fix use of titles for sheet names, to avoid KeyError
2 parents 01a5df4 + c788f58 commit 0927d6d

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

CHANGELOG.md

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

77
## [Unreleased]
88

9+
## [0.14.0] - 2020-09-29
10+
11+
### Fixed
12+
13+
- Fix use of titles for sheet names, to avoid KeyError when a field is missing from the schema
14+
15+
### Changed
16+
917
- Include sheet name with duplicate heading warnings.
1018

1119
## [0.13.0] - 2020-09-09

flattentool/json_input.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,11 @@ def parse_json_dict(
475475
sheet_key(sheet, parent_name + key + "/0/" + k)
476476
] = "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
477477

478-
if self.use_titles and self.schema_parser:
478+
if (
479+
self.use_titles
480+
and self.schema_parser
481+
and (parent_name, key,) in self.schema_parser.sub_sheet_titles
482+
):
479483
sub_sheet_name = self.schema_parser.sub_sheet_titles[
480484
(parent_name, key,)
481485
]

flattentool/tests/test_input_SpreadsheetInput_unflatten_mulitplesheets.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,18 @@
326326
{"ROOT_ID": 1, "Identifier": 2, "Arr title:C title": "3",},
327327
{"ROOT_ID": 1, "Identifier": 2, "Arr title:C title": "4",},
328328
],
329+
"arr_not_in_schema": [
330+
{"ROOT_ID": 1, "Identifier": 2, "arr_not_in_schema/0/testD": "5",},
331+
{"ROOT_ID": 1, "Identifier": 2, "arr_not_in_schema/0/testD": "6",},
332+
],
329333
},
330334
[
331-
{"ROOT_ID": 1, "id": 2, "testArr": [{"testC": "3"}, {"testC": "4"},]},
335+
{
336+
"ROOT_ID": 1,
337+
"id": 2,
338+
"testArr": [{"testC": "3"}, {"testC": "4"},],
339+
"arr_not_in_schema": [{"testD": "5"}, {"testD": "6"}],
340+
},
332341
{"ROOT_ID": 1, "id": 3},
333342
],
334343
[],

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="flattentool",
15-
version="0.13.0",
15+
version="0.14.0",
1616
author="Open Data Services",
1717
author_email="[email protected]",
1818
packages=["flattentool"],

0 commit comments

Comments
 (0)