Skip to content

Commit 3f9d8b6

Browse files
committed
fix: csvjoin uses the correct columns when performing a --right join, closes #1213
1 parent f6f7b27 commit 3f9d8b6

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

CHANGELOG.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Unreleased
22
----------
33

4+
* fix: :doc:`/scripts/csvjoin` uses the correct columns when performing a ``--right`` join.
45
* Drop Python 3.7 support (end-of-life was June 5, 2023).
56

67
1.1.1 - February 22, 2023

csvkit/utilities/csvjoin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def main(self):
9898
remaining_tables.reverse()
9999

100100
for i, table in enumerate(remaining_tables):
101-
jointab = agate.Table.join(jointab, table, join_column_ids[-(i + 2)], join_column_ids[-1])
101+
jointab = agate.Table.join(jointab, table, join_column_ids[-1], join_column_ids[-(i + 2)])
102102
elif self.args.outer_join:
103103
# Full outer join
104104
for i, table in enumerate(tables[1:]):

tests/test_utilities/test_csvjoin.py

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def test_right(self):
2929
output = self.get_output_as_io(['-c', 'a', '--right', 'examples/join_a.csv', 'examples/join_b.csv'])
3030
self.assertEqual(len(output.readlines()), 4)
3131

32+
def test_right_indices(self):
33+
output = self.get_output_as_io(['-c', '1,4', '--right', 'examples/join_a.csv', 'examples/blanks.csv'])
34+
self.assertEqual(len(output.readlines()), 2)
35+
3236
def test_outer(self):
3337
output = self.get_output_as_io(['-c', 'a', '--outer', 'examples/join_a.csv', 'examples/join_b.csv'])
3438
self.assertEqual(len(output.readlines()), 6)

0 commit comments

Comments
 (0)