From 3779425ccd9a4ceb58607ca56abee7e76e70b246 Mon Sep 17 00:00:00 2001 From: Omkar P <45419097+omkar-foss@users.noreply.github.com> Date: Fri, 23 Aug 2024 10:38:39 +0530 Subject: [PATCH] Remove option to return as list of tuples --- python/deltalake/table.py | 12 +++------- python/tests/test_table_read.py | 42 +++++++-------------------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/python/deltalake/table.py b/python/deltalake/table.py index 1ac5109f1f..45912c5cf4 100644 --- a/python/deltalake/table.py +++ b/python/deltalake/table.py @@ -513,25 +513,19 @@ def version(self) -> int: def partitions( self, partition_filters: Optional[List[Tuple[str, str, Any]]] = None, - as_tuple_list: bool = False, - ) -> List[Dict[str, str]] | List[Tuple[str]]: + ) -> List[Dict[str, str]]: """ Returns the partitions as a list of dicts. Example: `[{'month': '1', 'year': '2020', 'day': '1'}, ...]` Args: partition_filters: The partition filters that will be used for getting the matched partitions, defaults to `None` (no filtering). - as_tuple_list: If `True`, returns the partitions as a list of tuples. Example: `[(("day", "5"), ("month", "4"), ("year", "2021")), ...]` """ - partitions: List[Any] = [] + partitions: List[Dict[str, str]] = [] for partition in self._table.get_active_partitions(partition_filters): if not partition: continue - if as_tuple_list: - sorted_partition = sorted(partition, key=lambda x: x[0]) - partitions.append(tuple(sorted_partition)) - else: - partitions.append({k: v for (k, v) in partition}) + partitions.append({k: v for (k, v) in partition}) return partitions def files( diff --git a/python/tests/test_table_read.py b/python/tests/test_table_read.py index 3d9b7a27fe..1f6d768450 100644 --- a/python/tests/test_table_read.py +++ b/python/tests/test_table_read.py @@ -855,33 +855,17 @@ def test_partitions_partitioned_table(): assert partition in actual -def test_partitions_tuples_partitioned_table(): - table_path = "../crates/test/tests/data/delta-0.8.0-partitioned" - dt = DeltaTable(table_path) - expected = [ - (("day", "5"), ("month", "2"), ("year", "2020")), - (("day", "1"), ("month", "1"), ("year", "2020")), - (("day", "5"), ("month", "4"), ("year", "2021")), - (("day", "3"), ("month", "2"), ("year", "2020")), - (("day", "20"), ("month", "12"), ("year", "2021")), - (("day", "4"), ("month", "12"), ("year", "2021")), - ] - actual = dt.partitions(as_tuple_list=True) - assert len(expected) == len(actual) - for partition in expected: - partition in actual - - def test_partitions_filtering_partitioned_table(): table_path = "../crates/test/tests/data/delta-0.8.0-partitioned" dt = DeltaTable(table_path) expected = [ - (("day", "5"), ("month", "4"), ("year", "2021")), - (("day", "20"), ("month", "12"), ("year", "2021")), - (("day", "4"), ("month", "12"), ("year", "2021")), + {"day": "5", "month": "4", "year": "2021"}, + {"day": "20", "month": "12", "year": "2021"}, + {"day": "4", "month": "12", "year": "2021"}, ] + partition_filters = [("year", ">=", "2021")] - actual = dt.partitions(partition_filters=partition_filters, as_tuple_list=True) + actual = dt.partitions(partition_filters=partition_filters) assert len(expected) == len(actual) for partition in expected: partition in actual @@ -891,18 +875,10 @@ def test_partitions_special_partitioned_table(): table_path = "../crates/test/tests/data/delta-0.8.0-special-partition" dt = DeltaTable(table_path) - # Partitions as list of dicts (default). - expected_dict = [{"x": "A/A"}, {"x": "B B"}] - actual_dict = dt.partitions() - for partition in expected_dict: - partition in actual_dict - - # Partitions as list of tuples. - expected_tuple = [[("x", "B B")], [("x", "A/A")]] - actual_tuple = dt.partitions(as_tuple_list=True) - assert len(expected_tuple) == len(actual_tuple) - for partition in expected_tuple: - partition in actual_tuple + expected = [{"x": "A/A"}, {"x": "B B"}] + actual = dt.partitions() + for partition in expected: + partition in actual def test_partitions_unpartitioned_table():