4141from pyiceberg .io .pyarrow import _dataframe_to_data_files , schema_to_pyarrow
4242from pyiceberg .partitioning import UNPARTITIONED_PARTITION_SPEC , PartitionField , PartitionSpec
4343from pyiceberg .schema import Schema
44- from pyiceberg .table import AddSchemaUpdate , SetCurrentSchemaUpdate , TableProperties
44+ from pyiceberg .table import TableProperties
4545from pyiceberg .table .snapshots import Operation
4646from pyiceberg .table .sorting import NullOrder , SortDirection , SortField , SortOrder
47+ from pyiceberg .table .update import AddSchemaUpdate , SetCurrentSchemaUpdate
4748from pyiceberg .transforms import IdentityTransform
4849from pyiceberg .typedef import Identifier
4950from pyiceberg .types import BooleanType , IntegerType , LongType , NestedField , StringType
@@ -236,7 +237,11 @@ def test_create_table_with_default_warehouse_location(
236237
237238
238239def test_create_table_location_override (
239- catalog : Catalog , tmp_path : Path , table_schema_nested : Schema , test_table_identifier : Identifier , test_table_properties : dict
240+ catalog : Catalog ,
241+ tmp_path : Path ,
242+ table_schema_nested : Schema ,
243+ test_table_identifier : Identifier ,
244+ test_table_properties : dict [str , str ],
240245) -> None :
241246 test_partition_spec = PartitionSpec (PartitionField (name = "x" , transform = IdentityTransform (), source_id = 1 , field_id = 1000 ))
242247 new_location = f"file://{ tmp_path } /new_location"
@@ -272,12 +277,15 @@ def test_create_table_removes_trailing_slash_from_location(
272277
273278def test_create_tables_idempotency (catalog : Catalog ) -> None :
274279 # Second initialization should not fail even if tables are already created
275- catalog .create_tables ()
276- catalog .create_tables ()
280+ catalog .create_tables () # type: ignore[attr-defined]
281+ catalog .create_tables () # type: ignore[attr-defined]
277282
278283
279284def test_create_table_pyarrow_schema (
280- catalog : Catalog , pyarrow_schema_simple_without_ids : pa .Schema , test_table_identifier : Identifier , test_table_properties : dict
285+ catalog : Catalog ,
286+ pyarrow_schema_simple_without_ids : pa .Schema ,
287+ test_table_identifier : Identifier ,
288+ test_table_properties : dict [str , str ],
281289) -> None :
282290 namespace = Catalog .namespace_from (test_table_identifier )
283291 catalog .create_namespace (namespace )
@@ -544,7 +552,7 @@ def test_commit_table(catalog: Catalog, table_schema_nested: Schema, test_table_
544552 original_table_metadata_location = table .metadata_location
545553 original_table_last_updated_ms = table .metadata .last_updated_ms
546554
547- assert catalog ._parse_metadata_version (table .metadata_location ) == 0
555+ assert catalog ._parse_metadata_version (table .metadata_location ) == 0 # type: ignore[attr-defined]
548556 assert table .metadata .current_schema_id == 0
549557
550558 transaction = table .transaction ()
@@ -555,7 +563,7 @@ def test_commit_table(catalog: Catalog, table_schema_nested: Schema, test_table_
555563
556564 updated_table_metadata = table .metadata
557565
558- assert catalog ._parse_metadata_version (table .metadata_location ) == 1
566+ assert catalog ._parse_metadata_version (table .metadata_location ) == 1 # type: ignore[attr-defined]
559567 assert updated_table_metadata .current_schema_id == 1
560568 assert len (updated_table_metadata .schemas ) == 2
561569 new_schema = next (schema for schema in updated_table_metadata .schemas if schema .schema_id == 1 )
@@ -731,7 +739,9 @@ def test_table_writes_metadata_to_custom_location(
731739 schema = schema_to_pyarrow (table_schema_simple ),
732740 )
733741 table .append (df )
734- manifests = table .current_snapshot ().manifests (table .io )
742+ snapshot = table .current_snapshot ()
743+ assert snapshot is not None
744+ manifests = snapshot .manifests (table .io )
735745 location_provider = table .location_provider ()
736746
737747 assert location_provider .new_metadata_location ("" ).startswith (metadata_path )
@@ -744,7 +754,7 @@ def test_table_writes_metadata_to_default_path(
744754 catalog : Catalog ,
745755 test_table_identifier : Identifier ,
746756 table_schema_simple : Schema ,
747- test_table_properties : dict ,
757+ test_table_properties : dict [ str , str ] ,
748758) -> None :
749759 namespace = Catalog .namespace_from (test_table_identifier )
750760 catalog .create_namespace (namespace )
@@ -759,7 +769,9 @@ def test_table_writes_metadata_to_default_path(
759769 schema = schema_to_pyarrow (table_schema_simple ),
760770 )
761771 table .append (df )
762- manifests = table .current_snapshot ().manifests (table .io )
772+ snapshot = table .current_snapshot ()
773+ assert snapshot is not None
774+ manifests = snapshot .manifests (table .io )
763775 location_provider = table .location_provider ()
764776
765777 assert location_provider .new_metadata_location ("" ).startswith (metadata_path )
@@ -932,15 +944,15 @@ def test_add_column_with_statement(catalog: Catalog, table_schema_simple: Schema
932944# Namespace tests
933945
934946
935- def test_create_namespace (catalog : Catalog , test_namespace : Identifier , test_table_properties : dict ) -> None :
947+ def test_create_namespace (catalog : Catalog , test_namespace : Identifier , test_table_properties : dict [ str , str ] ) -> None :
936948 catalog .create_namespace (test_namespace , test_table_properties )
937- assert catalog ._namespace_exists (test_namespace )
949+ assert catalog ._namespace_exists (test_namespace ) # type: ignore[attr-defined]
938950 assert (Catalog .identifier_to_tuple (test_namespace )[:1 ]) in catalog .list_namespaces ()
939951 assert test_table_properties == catalog .load_namespace_properties (test_namespace )
940952
941953
942954def test_create_namespace_raises_error_on_existing_namespace (
943- catalog : Catalog , test_namespace : Identifier , test_table_properties : dict
955+ catalog : Catalog , test_namespace : Identifier , test_table_properties : dict [ str , str ]
944956) -> None :
945957 catalog .create_namespace (test_namespace , test_table_properties )
946958 with pytest .raises (NamespaceAlreadyExistsError ):
@@ -1003,12 +1015,16 @@ def test_get_namespace_metadata_raises_error_when_namespace_does_not_exist(catal
10031015def test_namespace_exists (catalog : Catalog ) -> None :
10041016 for ns in [("db1" ,), ("db1" , "ns1" ), ("db2" , "ns1" ), ("db3" , "ns1" , "ns2" )]:
10051017 catalog .create_namespace (ns )
1006- assert catalog ._namespace_exists (ns )
1018+ assert catalog ._namespace_exists (ns ) # type: ignore[attr-defined]
10071019
1008- assert catalog ._namespace_exists ("db2" ) # `db2` exists because `db2.ns1` exists
1009- assert catalog ._namespace_exists ("db3.ns1" ) # `db3.ns1` exists because `db3.ns1.ns2` exists
1010- assert not catalog ._namespace_exists ("db_" ) # make sure '_' is escaped in the query
1011- assert not catalog ._namespace_exists ("db%" ) # make sure '%' is escaped in the query
1020+ # `db2` exists because `db2.ns1` exists
1021+ assert catalog ._namespace_exists ("db2" ) # type: ignore[attr-defined]
1022+ # `db3.ns1` exists because `db3.ns1.ns2` exists
1023+ assert catalog ._namespace_exists ("db3.ns1" ) # type: ignore[attr-defined]
1024+ # make sure '_' is escaped in the query
1025+ assert not catalog ._namespace_exists ("db_" ) # type: ignore[attr-defined]
1026+ # make sure '%' is escaped in the query
1027+ assert not catalog ._namespace_exists ("db%" ) # type: ignore[attr-defined]
10121028
10131029
10141030# Namespace properties
@@ -1048,7 +1064,7 @@ def test_load_empty_namespace_properties(catalog: Catalog, test_namespace: Ident
10481064def test_list_namespaces (catalog : Catalog ) -> None :
10491065 namespace_list = ["db" , "db.ns1" , "db.ns1.ns2" , "db.ns2" , "db2" , "db2.ns1" , "db%" ]
10501066 for namespace in namespace_list :
1051- if not catalog ._namespace_exists (namespace ):
1067+ if not catalog ._namespace_exists (namespace ): # type: ignore[attr-defined]
10521068 catalog .create_namespace (namespace )
10531069
10541070 ns_list = catalog .list_namespaces ()
@@ -1068,7 +1084,7 @@ def test_list_namespaces(catalog: Catalog) -> None:
10681084def test_list_namespaces_fuzzy_match (catalog : Catalog ) -> None :
10691085 namespace_list = ["db.ns1" , "db.ns1.ns2" , "db.ns2" , "db.ns1X.ns3" , "db_.ns1.ns2" , "db2.ns1.ns2" ]
10701086 for namespace in namespace_list :
1071- if not catalog ._namespace_exists (namespace ):
1087+ if not catalog ._namespace_exists (namespace ): # type: ignore[attr-defined]
10721088 catalog .create_namespace (namespace )
10731089
10741090 assert catalog .list_namespaces ("db.ns1" ) == [("db" , "ns1" , "ns2" )]
@@ -1124,7 +1140,7 @@ def test_update_namespace_metadata(catalog: Catalog, test_namespace: Identifier,
11241140 catalog .create_namespace (test_namespace , test_table_properties )
11251141 new_metadata = {"key3" : "value3" , "key4" : "value4" }
11261142 summary = catalog .update_namespace_properties (test_namespace , updates = new_metadata )
1127- assert catalog ._namespace_exists (test_namespace )
1143+ assert catalog ._namespace_exists (test_namespace ) # type: ignore[attr-defined]
11281144 assert new_metadata .items () <= catalog .load_namespace_properties (test_namespace ).items ()
11291145 assert summary .removed == []
11301146 assert sorted (summary .updated ) == ["key3" , "key4" ]
@@ -1138,7 +1154,7 @@ def test_update_namespace_metadata_removals(
11381154 new_metadata = {"key3" : "value3" , "key4" : "value4" }
11391155 remove_metadata = {"key1" }
11401156 summary = catalog .update_namespace_properties (test_namespace , remove_metadata , new_metadata )
1141- assert catalog ._namespace_exists (test_namespace )
1157+ assert catalog ._namespace_exists (test_namespace ) # type: ignore[attr-defined]
11421158 assert new_metadata .items () <= catalog .load_namespace_properties (test_namespace ).items ()
11431159 assert remove_metadata .isdisjoint (catalog .load_namespace_properties (test_namespace ).keys ())
11441160 assert summary .removed == ["key1" ]
@@ -1152,13 +1168,13 @@ def test_update_namespace_metadata_removals(
11521168def test_drop_namespace (catalog : Catalog , table_schema_nested : Schema , test_table_identifier : Identifier ) -> None :
11531169 namespace = Catalog .namespace_from (test_table_identifier )
11541170 catalog .create_namespace (namespace )
1155- assert catalog ._namespace_exists (namespace )
1171+ assert catalog ._namespace_exists (namespace ) # type: ignore[attr-defined]
11561172 catalog .create_table (test_table_identifier , table_schema_nested )
11571173 with pytest .raises (NamespaceNotEmptyError ):
11581174 catalog .drop_namespace (namespace )
11591175 catalog .drop_table (test_table_identifier )
11601176 catalog .drop_namespace (namespace )
1161- assert not catalog ._namespace_exists (namespace )
1177+ assert not catalog ._namespace_exists (namespace ) # type: ignore[attr-defined]
11621178
11631179
11641180def test_drop_namespace_raises_error_when_namespace_does_not_exist (catalog : Catalog ) -> None :
0 commit comments