From 66222ec0320ff6a4e652fef067e9fa7da6b704ee Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Tue, 3 Oct 2023 22:40:35 -0400 Subject: [PATCH] fix: Allow consecutive calls to Table.group_by, closes #765 --- CHANGELOG.rst | 5 +++++ agate/tableset/__init__.py | 7 ++++++- docs/conf.py | 1 + tests/test_table/test_group_by.py | 5 +++++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 6d1ad98a..7827bf62 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,3 +1,8 @@ +1.7.2 +----- + +* Fix consecutive calls to :meth:`.Table.group_by`. (#765) + 1.7.1 - Jan 4, 2023 ------------------- diff --git a/agate/tableset/__init__.py b/agate/tableset/__init__.py index 4876d00b..7e70236f 100644 --- a/agate/tableset/__init__.py +++ b/agate/tableset/__init__.py @@ -148,7 +148,12 @@ def _proxy(self, method_name, *args, **kwargs): tables = [] for key, table in self.items(): - tables.append(getattr(table, method_name)(*args, **kwargs)) + result = getattr(table, method_name)(*args, **kwargs) + if isinstance(result, TableSet): + for table in result.values(): + tables.append(table) + else: + tables.append(result) return self._fork( tables, diff --git a/docs/conf.py b/docs/conf.py index fa64aab8..4c341464 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -36,6 +36,7 @@ autodoc_default_options = { 'members': None, + 'member-order': 'bysource', 'show-inheritance': True, } diff --git a/tests/test_table/test_group_by.py b/tests/test_table/test_group_by.py index cb51ffd4..6178a3a8 100644 --- a/tests/test_table/test_group_by.py +++ b/tests/test_table/test_group_by.py @@ -108,3 +108,8 @@ def test_group_by_bad_column(self): with self.assertRaises(KeyError): table.group_by('bad') + + def test_group_by_twice(self): + table = Table(self.rows, self.column_names, self.column_types) + + repr(table.group_by('one').group_by('two'))