diff --git a/pyiceberg/io/__init__.py b/pyiceberg/io/__init__.py index ec232a02eb..e433ed88a5 100644 --- a/pyiceberg/io/__init__.py +++ b/pyiceberg/io/__init__.py @@ -379,14 +379,14 @@ def load_file_io(properties: Properties = EMPTY_DICT, location: str | None = Non raise ValueError(f"Could not initialize FileIO: {io_impl}") # Check the table location - if location: - if file_io := _infer_file_io_from_scheme(location, properties): - return file_io + if location and (file_io := _infer_file_io_from_scheme(location, properties)): + return file_io # Look at the schema of the warehouse - if warehouse_location := properties.get(WAREHOUSE): - if file_io := _infer_file_io_from_scheme(warehouse_location, properties): - return file_io + if (warehouse_location := properties.get(WAREHOUSE)) and ( + file_io := _infer_file_io_from_scheme(warehouse_location, properties) + ): + return file_io try: # Default to PyArrow diff --git a/pyiceberg/partitioning.py b/pyiceberg/partitioning.py index 3d06287b6c..99fd2f0b75 100644 --- a/pyiceberg/partitioning.py +++ b/pyiceberg/partitioning.py @@ -110,17 +110,16 @@ def __init__( @model_validator(mode="before") @classmethod def map_source_ids_onto_source_id(cls, data: Any) -> Any: - if isinstance(data, dict): - if "source-ids" in data: - if "source-id" in data: - raise ValueError("source-id and source-ids are mutually exclusive") - source_ids = data["source-ids"] - if isinstance(source_ids, list): - if len(source_ids) == 0: - raise ValueError("Empty source-ids is not allowed") - if len(source_ids) > 1: - raise ValueError("Multi argument transforms are not yet supported") - data["source-id"] = source_ids[0] + if isinstance(data, dict) and "source-ids" in data: + if "source-id" in data: + raise ValueError("source-id and source-ids are mutually exclusive") + source_ids = data["source-ids"] + if isinstance(source_ids, list): + if len(source_ids) == 0: + raise ValueError("Empty source-ids is not allowed") + if len(source_ids) > 1: + raise ValueError("Multi argument transforms are not yet supported") + data["source-id"] = source_ids[0] return data def __str__(self) -> str: diff --git a/pyiceberg/table/metadata.py b/pyiceberg/table/metadata.py index 8236f12229..d0e7496005 100644 --- a/pyiceberg/table/metadata.py +++ b/pyiceberg/table/metadata.py @@ -434,9 +434,8 @@ def set_v2_compatible_defaults(cls, data: dict[str, Any]) -> dict[str, Any]: """ # When the schema doesn't have an ID schema = data.get("schema") - if isinstance(schema, dict): - if "schema_id" not in schema and "schema-id" not in schema: - schema["schema_id"] = DEFAULT_SCHEMA_ID + if isinstance(schema, dict) and "schema_id" not in schema and "schema-id" not in schema: + schema["schema_id"] = DEFAULT_SCHEMA_ID return data diff --git a/pyiceberg/table/sorting.py b/pyiceberg/table/sorting.py index 76bc109935..aed348a265 100644 --- a/pyiceberg/table/sorting.py +++ b/pyiceberg/table/sorting.py @@ -100,17 +100,16 @@ def set_null_order(cls, values: dict[str, Any]) -> dict[str, Any]: @model_validator(mode="before") @classmethod def map_source_ids_onto_source_id(cls, data: Any) -> Any: - if isinstance(data, dict): - if "source-ids" in data: - if "source-id" in data: - raise ValueError("source-id and source-ids are mutually exclusive") - source_ids = data["source-ids"] - if isinstance(source_ids, list): - if len(source_ids) == 0: - raise ValueError("Empty source-ids is not allowed") - if len(source_ids) > 1: - raise ValueError("Multi argument transforms are not yet supported") - data["source-id"] = source_ids[0] + if isinstance(data, dict) and "source-ids" in data: + if "source-id" in data: + raise ValueError("source-id and source-ids are mutually exclusive") + source_ids = data["source-ids"] + if isinstance(source_ids, list): + if len(source_ids) == 0: + raise ValueError("Empty source-ids is not allowed") + if len(source_ids) > 1: + raise ValueError("Multi argument transforms are not yet supported") + data["source-id"] = source_ids[0] return data source_id: int = Field(alias="source-id")