Project

General

Profile

« Previous | Next » 

Revision 4158

union: Multi-support: When an input appears in both maps, treat an empty mapping as if it didn't exist so that it doesn't overwrite a non-empty mapping in the other map

View differences:

bin/union
1 1
#!/usr/bin/env python
2 2
# Combines two map spreadsheets A0->B and A1->C to A->B, with B overwriting C
3 3
# Multi-safe (supports an input appearing multiple times). Note that if there is
4
# *any* mapping for an input in map_0, all mappings for that input in map_1 will
5
# be excluded.
4
# *any* non-empty mapping for an input in map_0, all mappings for that input in
5
# map_1 will be excluded.
6 6

  
7 7
import csv
8 8
import os.path
......
46 46
    writer.writerow(maps.merge_headers(*headers, **dict(prefer=header_num)))
47 47
    mappings = set()
48 48
    for row in map_0_reader:
49
        if not all_ and row[0] != '':
49
        if not all_ and row[0] != '' and row[1] != '':
50 50
            mappings.add(row[0])
51
            if row[1] != '': mappings.add(row[1])
51
            mappings.add(row[1])
52 52
        writer.writerow(row)
53 53
    
54 54
    if combinable:

Also available in: Unified diff