From a4d5b2a3eba1571419ef1fe142ad7f0ad99085ca Mon Sep 17 00:00:00 2001 From: jayce Date: Wed, 13 Sep 2023 19:17:41 -0400 Subject: [PATCH 1/8] Python: Add `__repr__` for `Table` and `Catalog` --- python/pyiceberg/catalog/__init__.py | 4 ++++ python/pyiceberg/table/__init__.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/python/pyiceberg/catalog/__init__.py b/python/pyiceberg/catalog/__init__.py index dafef71287ab..55df40b6bc69 100644 --- a/python/pyiceberg/catalog/__init__.py +++ b/python/pyiceberg/catalog/__init__.py @@ -600,3 +600,7 @@ def _get_updated_props_and_update_summary( ) return properties_update_summary, updated_properties + + def __repr__(self) -> str: + """Returns the string representation of the Catalog class.""" + return f"{self.__class__} with name: {self.name} and properties: {self.properties}" diff --git a/python/pyiceberg/table/__init__.py b/python/pyiceberg/table/__init__.py index b905c955c848..7dbba9e7a5bd 100644 --- a/python/pyiceberg/table/__init__.py +++ b/python/pyiceberg/table/__init__.py @@ -541,6 +541,9 @@ def __eq__(self, other: Any) -> bool: else False ) + def __repr__(self) -> str: + return f"{self.__class__} \n Identifier: {self.identifier} \n IO: {self.io} \n Catalog: {self.catalog.__class__}" + class StaticTable(Table): """Load a table directly from a metadata file (i.e., without using a catalog).""" From 96252aa39e754705f841e4e3b1dd11cfae38e949 Mon Sep 17 00:00:00 2001 From: jayceslesar Date: Wed, 20 Sep 2023 17:13:54 -0400 Subject: [PATCH 2/8] remove properties in `__repr__` output --- python/pyiceberg/catalog/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyiceberg/catalog/__init__.py b/python/pyiceberg/catalog/__init__.py index 55df40b6bc69..393077fb2afa 100644 --- a/python/pyiceberg/catalog/__init__.py +++ b/python/pyiceberg/catalog/__init__.py @@ -603,4 +603,4 @@ def _get_updated_props_and_update_summary( def __repr__(self) -> str: """Returns the string representation of the Catalog class.""" - return f"{self.__class__} with name: {self.name} and properties: {self.properties}" + return f"{self.__class__} with name: {self.name}" From 9f4533cf73b74da7e9fb8cf33554388d1c510b68 Mon Sep 17 00:00:00 2001 From: jayceslesar Date: Wed, 20 Sep 2023 17:14:29 -0400 Subject: [PATCH 3/8] remove table `__repr__` --- python/pyiceberg/table/__init__.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/python/pyiceberg/table/__init__.py b/python/pyiceberg/table/__init__.py index 7dbba9e7a5bd..b905c955c848 100644 --- a/python/pyiceberg/table/__init__.py +++ b/python/pyiceberg/table/__init__.py @@ -541,9 +541,6 @@ def __eq__(self, other: Any) -> bool: else False ) - def __repr__(self) -> str: - return f"{self.__class__} \n Identifier: {self.identifier} \n IO: {self.io} \n Catalog: {self.catalog.__class__}" - class StaticTable(Table): """Load a table directly from a metadata file (i.e., without using a catalog).""" From 6d7acfc4ee320704736e15d1066cd73d379a9e1f Mon Sep 17 00:00:00 2001 From: jayceslesar Date: Fri, 22 Sep 2023 10:06:29 -0400 Subject: [PATCH 4/8] clean up catalog __repr__ and add test --- python/pyiceberg/catalog/__init__.py | 2 +- python/tests/catalog/test_base.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/python/pyiceberg/catalog/__init__.py b/python/pyiceberg/catalog/__init__.py index 393077fb2afa..625e7957de85 100644 --- a/python/pyiceberg/catalog/__init__.py +++ b/python/pyiceberg/catalog/__init__.py @@ -603,4 +603,4 @@ def _get_updated_props_and_update_summary( def __repr__(self) -> str: """Returns the string representation of the Catalog class.""" - return f"{self.__class__} with name: {self.name}" + return f"{self.name} ({self.__class__})" diff --git a/python/tests/catalog/test_base.py b/python/tests/catalog/test_base.py index d1d7d638a67b..c776c9f25495 100644 --- a/python/tests/catalog/test_base.py +++ b/python/tests/catalog/test_base.py @@ -598,3 +598,8 @@ def test_add_column_with_statement(catalog: InMemoryCatalog) -> None: schema_id=0, identifier_field_ids=[], ) + + +def test_catalog_repr(catalog: InMemoryCatalog) -> None: + s = str(catalog) + assert s == "test.in.memory.catalog ()" \ No newline at end of file From 56fc522f87b8c85efe98ec19c5bc4e2bc7301bca Mon Sep 17 00:00:00 2001 From: jayceslesar Date: Fri, 22 Sep 2023 10:55:04 -0400 Subject: [PATCH 5/8] actually use repr instead of str --- python/tests/catalog/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/catalog/test_base.py b/python/tests/catalog/test_base.py index c776c9f25495..a06243c0c04c 100644 --- a/python/tests/catalog/test_base.py +++ b/python/tests/catalog/test_base.py @@ -601,5 +601,5 @@ def test_add_column_with_statement(catalog: InMemoryCatalog) -> None: def test_catalog_repr(catalog: InMemoryCatalog) -> None: - s = str(catalog) + s = catalog.__repr__() assert s == "test.in.memory.catalog ()" \ No newline at end of file From 2b84a11ad3c6d2bdb161f5b8802f8491b882a515 Mon Sep 17 00:00:00 2001 From: Jayce Slesar <47452474+jayceslesar@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:08:57 -0400 Subject: [PATCH 6/8] Update python/tests/catalog/test_base.py Co-authored-by: Fokko Driesprong --- python/tests/catalog/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/catalog/test_base.py b/python/tests/catalog/test_base.py index a06243c0c04c..8d0615d7e0d8 100644 --- a/python/tests/catalog/test_base.py +++ b/python/tests/catalog/test_base.py @@ -601,5 +601,5 @@ def test_add_column_with_statement(catalog: InMemoryCatalog) -> None: def test_catalog_repr(catalog: InMemoryCatalog) -> None: - s = catalog.__repr__() + s = repr(catalog) assert s == "test.in.memory.catalog ()" \ No newline at end of file From 850391f71a09c70402ca5d43be8e0f575b4e7f69 Mon Sep 17 00:00:00 2001 From: Fokko Driesprong Date: Fri, 22 Sep 2023 17:27:52 +0200 Subject: [PATCH 7/8] Update python/pyiceberg/catalog/__init__.py --- python/pyiceberg/catalog/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/pyiceberg/catalog/__init__.py b/python/pyiceberg/catalog/__init__.py index 625e7957de85..2577a97bc1f2 100644 --- a/python/pyiceberg/catalog/__init__.py +++ b/python/pyiceberg/catalog/__init__.py @@ -602,5 +602,5 @@ def _get_updated_props_and_update_summary( return properties_update_summary, updated_properties def __repr__(self) -> str: - """Returns the string representation of the Catalog class.""" + """Return the string representation of the Catalog class.""" return f"{self.name} ({self.__class__})" From 6eb0e1860bfac153755ba2a63868923c5105f549 Mon Sep 17 00:00:00 2001 From: Fokko Driesprong Date: Fri, 22 Sep 2023 17:33:23 +0200 Subject: [PATCH 8/8] Update python/tests/catalog/test_base.py --- python/tests/catalog/test_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/catalog/test_base.py b/python/tests/catalog/test_base.py index 8d0615d7e0d8..da121f6114f9 100644 --- a/python/tests/catalog/test_base.py +++ b/python/tests/catalog/test_base.py @@ -602,4 +602,4 @@ def test_add_column_with_statement(catalog: InMemoryCatalog) -> None: def test_catalog_repr(catalog: InMemoryCatalog) -> None: s = repr(catalog) - assert s == "test.in.memory.catalog ()" \ No newline at end of file + assert s == "test.in.memory.catalog ()"