Skip to content

Commit

Permalink
fix: csvjoin uses the correct columns when performing a --right join, c…
Browse files Browse the repository at this point in the history
…loses #1213
  • Loading branch information
jpmckinney committed Oct 4, 2023
1 parent f6f7b27 commit 3f9d8b6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Unreleased
----------

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

1.1.1 - February 22, 2023
Expand Down
2 changes: 1 addition & 1 deletion csvkit/utilities/csvjoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def main(self):
remaining_tables.reverse()

for i, table in enumerate(remaining_tables):
jointab = agate.Table.join(jointab, table, join_column_ids[-(i + 2)], join_column_ids[-1])
jointab = agate.Table.join(jointab, table, join_column_ids[-1], join_column_ids[-(i + 2)])
elif self.args.outer_join:
# Full outer join
for i, table in enumerate(tables[1:]):
Expand Down
4 changes: 4 additions & 0 deletions tests/test_utilities/test_csvjoin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def test_right(self):
output = self.get_output_as_io(['-c', 'a', '--right', 'examples/join_a.csv', 'examples/join_b.csv'])
self.assertEqual(len(output.readlines()), 4)

def test_right_indices(self):
output = self.get_output_as_io(['-c', '1,4', '--right', 'examples/join_a.csv', 'examples/blanks.csv'])
self.assertEqual(len(output.readlines()), 2)

def test_outer(self):
output = self.get_output_as_io(['-c', 'a', '--outer', 'examples/join_a.csv', 'examples/join_b.csv'])
self.assertEqual(len(output.readlines()), 6)
Expand Down

0 comments on commit 3f9d8b6

Please sign in to comment.