Revision 4164
Added by Aaron Marcuse-Kubitza over 12 years ago
union | ||
---|---|---|
14 | 14 |
import opts |
15 | 15 |
import util |
16 | 16 |
|
17 |
def non_empty(row): return row[0] != '' and row[1] != '' |
|
18 |
|
|
17 | 19 |
def main(): |
18 | 20 |
ignore = opts.env_flag('ignore') |
19 | 21 |
header_num = util.cast(int, opts.get_env_var('header_num')) |
... | ... | |
46 | 48 |
writer.writerow(maps.merge_headers(*headers, **dict(prefer=header_num))) |
47 | 49 |
mappings = set() |
48 | 50 |
for row in map_0_reader: |
49 |
if not all_ and row[0] != '' and row[1] != '': |
|
50 |
mappings.add(row[0]) |
|
51 |
mappings.add(row[1]) |
|
52 |
writer.writerow(row) |
|
51 |
if all_ or non_empty(row): |
|
52 |
if not all_: |
|
53 |
mappings.add(row[0]) |
|
54 |
mappings.add(row[1]) |
|
55 |
writer.writerow(row) |
|
53 | 56 |
|
54 | 57 |
if combinable: |
55 | 58 |
# Add mappings in map 1 that weren't already defined or mapped to |
56 | 59 |
for row in map_1_reader: |
57 |
if row[0] != '' and row[0] not in mappings: writer.writerow(row)
|
|
60 |
if non_empty(row) and row[0] not in mappings: writer.writerow(row)
|
|
58 | 61 |
|
59 | 62 |
stream.close() |
60 | 63 |
|
Also available in: Unified diff
union: Exclude empty rows from the output, so that empty mappings from map_0 aren't included when map_1 contains a non-empty mapping for the same term. Note that this causes "No non-empty join mapping" warnings to turn into "No join mapping".