diff --git a/python/pyiceberg/table/__init__.py b/python/pyiceberg/table/__init__.py index 6621348eb979..9d585118f96d 100644 --- a/python/pyiceberg/table/__init__.py +++ b/python/pyiceberg/table/__init__.py @@ -541,12 +541,12 @@ def __eq__(self, other: Any) -> bool: ) def __repr__(self) -> str: - """Returns the string representation of the Table class.""" + """Return the string representation of the Table class.""" table_name = self.catalog.table_name_from(self.identifier) - schema_str = ',\n '.join(f'{column.name}: {column.field_type}' for column in self.schema().columns) - partition_str = ', '.join(field.name for field in self.spec().fields) - snapshot_str = str(self.current_snapshot()) if self.current_snapshot() else 'null' - result_str = f'{table_name}(\n {schema_str}\n),\npartition by: [{partition_str}],\nsnapshot: {snapshot_str}' + schema_str = ",\n ".join(f"{column.name}: {column.field_type}" for column in self.schema().columns) + partition_str = ", ".join(field.name for field in self.spec().fields) + snapshot_str = str(self.current_snapshot()) if self.current_snapshot() else "null" + result_str = f"{table_name}(\n {schema_str}\n),\npartition by: [{partition_str}],\nsnapshot: {snapshot_str}" return result_str diff --git a/python/tests/table/test_init.py b/python/tests/table/test_init.py index b25e445032fd..263f4cba8316 100644 --- a/python/tests/table/test_init.py +++ b/python/tests/table/test_init.py @@ -193,6 +193,17 @@ def test_snapshot_by_name_does_not_exist(table: Table) -> None: assert table.snapshot_by_name("doesnotexist") is None +def test_repr(table: Table) -> None: + expected = """table( + x: long, + y: long, + z: long +), +partition by: [x], +snapshot: Operation.APPEND: id=3055729675574597004, parent_id=3051729675574597004, schema_id=1""" + assert repr(table) == expected + + def test_history(table: Table) -> None: assert table.history() == [ SnapshotLogEntry(snapshot_id=3051729675574597004, timestamp_ms=1515100955770),