From e1df6b8929fffa0feccee6f114da5179c7728e38 Mon Sep 17 00:00:00 2001 From: jayceslesar Date: Tue, 10 Jun 2025 19:49:09 -0400 Subject: [PATCH] chore: remove non-test asserts --- pyiceberg/catalog/dynamodb.py | 4 +++- pyiceberg/catalog/glue.py | 15 +++++++++++---- pyiceberg/cli/console.py | 2 -- pyiceberg/schema.py | 4 ++-- pyiceberg/utils/config.py | 3 ++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/pyiceberg/catalog/dynamodb.py b/pyiceberg/catalog/dynamodb.py index 63466b0142..41a519a208 100644 --- a/pyiceberg/catalog/dynamodb.py +++ b/pyiceberg/catalog/dynamodb.py @@ -824,7 +824,9 @@ def _convert_dynamo_item_to_regular_dict(dynamo_json: Dict[str, Any]) -> Dict[st raise ValueError("Only S and N data types are supported.") values = list(val_dict.values()) - assert len(values) == 1 + if len(values) != 1: + raise ValueError(f"Expecting only 1 value: {values}") + column_value = values[0] regular_json[column_name] = column_value diff --git a/pyiceberg/catalog/glue.py b/pyiceberg/catalog/glue.py index 01bb0e9b05..517630d241 100644 --- a/pyiceberg/catalog/glue.py +++ b/pyiceberg/catalog/glue.py @@ -252,7 +252,9 @@ def _construct_table_input( def _construct_rename_table_input(to_table_name: str, glue_table: TableTypeDef) -> TableInputTypeDef: rename_table_input: TableInputTypeDef = {"Name": to_table_name} # use the same Glue info to create the new table, pointing to the old metadata - assert glue_table["TableType"] + if not glue_table["TableType"]: + raise ValueError("Glue table type is missing, cannot rename table") + rename_table_input["TableType"] = glue_table["TableType"] if "Owner" in glue_table: rename_table_input["Owner"] = glue_table["Owner"] @@ -347,9 +349,14 @@ def __init__(self, name: str, client: Optional[GlueClient] = None, **properties: def _convert_glue_to_iceberg(self, glue_table: TableTypeDef) -> Table: properties: Properties = glue_table["Parameters"] - assert glue_table["DatabaseName"] - assert glue_table["Parameters"] - database_name = glue_table["DatabaseName"] + database_name = glue_table.get("DatabaseName", None) + if database_name is None: + raise ValueError("Glue table is missing DatabaseName property") + + parameters = glue_table.get("Parameters", None) + if parameters is None: + raise ValueError("Glue table is missing Parameters property") + table_name = glue_table["Name"] if TABLE_TYPE not in properties: diff --git a/pyiceberg/cli/console.py b/pyiceberg/cli/console.py index 83e67a3cbb..25a536d2a6 100644 --- a/pyiceberg/cli/console.py +++ b/pyiceberg/cli/console.py @@ -300,7 +300,6 @@ def get_namespace(ctx: Context, identifier: str, property_name: str) -> None: identifier_tuple = Catalog.identifier_to_tuple(identifier) namespace_properties = catalog.load_namespace_properties(identifier_tuple) - assert namespace_properties if property_name: if property_value := namespace_properties.get(property_name): @@ -322,7 +321,6 @@ def get_table(ctx: Context, identifier: str, property_name: str) -> None: identifier_tuple = Catalog.identifier_to_tuple(identifier) metadata = catalog.load_table(identifier_tuple).metadata - assert metadata if property_name: if property_value := metadata.properties.get(property_name): diff --git a/pyiceberg/schema.py b/pyiceberg/schema.py index 6aa1f88852..6333ace6e2 100644 --- a/pyiceberg/schema.py +++ b/pyiceberg/schema.py @@ -1362,8 +1362,8 @@ def make_compatible_name(name: str) -> str: def _valid_avro_name(name: str) -> bool: - length = len(name) - assert length > 0, ValueError("Can not validate empty avro name") + if not len(name): + raise ValueError("Can not validate empty avro name") first = name[0] if not (first.isalpha() or first == "_"): return False diff --git a/pyiceberg/utils/config.py b/pyiceberg/utils/config.py index 0c162777d6..0bfaefdbc6 100644 --- a/pyiceberg/utils/config.py +++ b/pyiceberg/utils/config.py @@ -154,7 +154,8 @@ def get_catalog_config(self, catalog_name: str) -> Optional[RecursiveDict]: raise ValueError(f"Catalog configurations needs to be an object: {catalog_name}") if catalog_name_lower in catalogs: catalog_conf = catalogs[catalog_name_lower] - assert isinstance(catalog_conf, dict), f"Configuration path catalogs.{catalog_name_lower} needs to be an object" + if not isinstance(catalog_conf, dict): + raise ValueError(f"Configuration path catalogs.{catalog_name_lower} needs to be an object") return catalog_conf return None