Skip to content

Commit be1944a

Browse files
committed
[#130] Add ignore command
1 parent f4b44c5 commit be1944a

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

flattentool/input.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,17 @@ def get_sheet_headings(self, sheet_name):
490490
sheet_configuration = {}
491491

492492
skip_rows = sheet_configuration.get("skipRows", 0)
493+
if sheet_configuration.get("ignore"):
494+
# returning empty headers is a proxy for no data in the sheet.
495+
return []
493496

494497
if self.vertical_orientation:
495498
return [cell.value for cell in worksheet.columns[skip_rows][configuration_line:]]
496499

497500
try:
498501
return [cell.value for cell in worksheet.rows[skip_rows + configuration_line]]
499502
except IndexError:
503+
# If the heading line is after data in the spreadsheet. i.e when skipRows
500504
return []
501505

502506
def get_sheet_configuration(self, sheet_name):

flattentool/lib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ def parse_sheet_configuration(configuration_list):
1313
configuration['skipRows'] = max(int(parts[1]), 0)
1414
if (len(parts) == 2 and parts[0].lower() == "headerrows" and isint(parts[1])):
1515
configuration['headerRows'] = max(int(parts[1]), 1)
16+
if (len(parts) == 1 and parts[0].lower() == "ignore"):
17+
configuration['ignore'] = True
1618
return configuration
5.82 KB
Binary file not shown.

flattentool/tests/test_init.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,3 +1198,17 @@ def test_commands_single_sheet_default(tmpdir):
11981198
unflattened = json.load(tmpdir.join('command_single_unflattened.json'))
11991199

12001200
assert unflattened == {'main': [{'actual': 'other', 'headings': 'headings', 'some': 'some'}, {'actual': 'actual', 'headings': 'data', 'some': 'some'}]}
1201+
1202+
def test_commands_ignore(tmpdir):
1203+
1204+
unflatten(
1205+
'flattentool/tests/fixtures/xlsx/commands_ignore.xlsx',
1206+
input_format='xlsx',
1207+
output_name=tmpdir.join('command_single_unflattened.json').strpath,
1208+
cell_source_map=tmpdir.join('command_single_source_map.json').strpath,
1209+
heading_source_map=tmpdir.join('command_single_heading_source_map.json').strpath,
1210+
)
1211+
1212+
unflattened = json.load(tmpdir.join('command_single_unflattened.json'))
1213+
1214+
assert unflattened == {'main': [{'actual': 'actual', 'headings': 'data', 'some': 'some'}]}

0 commit comments

Comments
 (0)