From 3f9d8b6f4af359a109ff5dd76bb886b53ce230fc Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Wed, 4 Oct 2023 00:08:32 -0400 Subject: [PATCH] fix: csvjoin uses the correct columns when performing a --right join, closes #1213 --- CHANGELOG.rst | 1 + csvkit/utilities/csvjoin.py | 2 +- tests/test_utilities/test_csvjoin.py | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 1b86c3250..7d33b7557 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 diff --git a/csvkit/utilities/csvjoin.py b/csvkit/utilities/csvjoin.py index d8ad737d2..dc7f71fe6 100644 --- a/csvkit/utilities/csvjoin.py +++ b/csvkit/utilities/csvjoin.py @@ -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:]): diff --git a/tests/test_utilities/test_csvjoin.py b/tests/test_utilities/test_csvjoin.py index b7cb39ff2..ce1e15a72 100644 --- a/tests/test_utilities/test_csvjoin.py +++ b/tests/test_utilities/test_csvjoin.py @@ -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)