From e9e33c48d3d038a76b92f8456ffb0567ede5a926 Mon Sep 17 00:00:00 2001 From: Anthony Lam Date: Sun, 8 Sep 2024 14:03:58 -0700 Subject: [PATCH 1/4] fix: Invert logic in StructType --- pyiceberg/types.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyiceberg/types.py b/pyiceberg/types.py index 97ddea0e57..8fa745384d 100644 --- a/pyiceberg/types.py +++ b/pyiceberg/types.py @@ -377,13 +377,13 @@ def field(self, field_id: int) -> Optional[NestedField]: def field_by_name(self, name: str, case_sensitive: bool = True) -> Optional[NestedField]: if case_sensitive: - name_lower = name.lower() for field in self.fields: - if field.name.lower() == name_lower: + if field.name == name: return field else: + name_lower = name.lower() for field in self.fields: - if field.name == name: + if field.name.lower() == name_lower: return field return None From 38ecf5eb8415e392db46ba202ec30d4c7d88fa20 Mon Sep 17 00:00:00 2001 From: Anthony Lam Date: Mon, 9 Sep 2024 10:59:39 -0700 Subject: [PATCH 2/4] Add test for StructType.field_by_name --- tests/test_types.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_types.py b/tests/test_types.py index 52bdce4de8..e029d7c5db 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -148,6 +148,18 @@ def test_struct_type() -> None: assert type_var != StructType(NestedField(1, "optional_field", IntegerType(), required=True)) assert type_var == pickle.loads(pickle.dumps(type_var)) +def test_struct_field_by_name() -> None: + lower_field = NestedField(1, "lower_case_field", IntegerType(), required=True), + upper_field = NestedField(2, "UPPER_CASE_FIELD", IntegerType(), required=True), + type_var = StructType(lower_field, upper_field, mixed_field) + + assert type_var.field_by_name("lower_case_field", case_sensitive=False) == lower_field + assert type_var.field_by_name("upper_case_field", case_sensitive=False) == upper_field + assert type_var.field_by_name("nonexistent_field", case_sensitive=False) is None + + assert type_var.field_by_name("lower_case_field", case_sensitive=True) == lower_field + assert type_var.field_by_name("upper_case_field", case_sensitive=True) is None + assert type_var.field_by_name("nonexistent_field", case_sensitive=True) is None def test_list_type() -> None: type_var = ListType( From 8d829f5361c8fa9277a9de322118b8f297513e4e Mon Sep 17 00:00:00 2001 From: Anthony Lam Date: Mon, 9 Sep 2024 11:56:09 -0700 Subject: [PATCH 3/4] Remove var I forgot about. --- tests/test_types.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_types.py b/tests/test_types.py index e029d7c5db..fc67a214e6 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -151,7 +151,7 @@ def test_struct_type() -> None: def test_struct_field_by_name() -> None: lower_field = NestedField(1, "lower_case_field", IntegerType(), required=True), upper_field = NestedField(2, "UPPER_CASE_FIELD", IntegerType(), required=True), - type_var = StructType(lower_field, upper_field, mixed_field) + type_var = StructType(lower_field, upper_field) assert type_var.field_by_name("lower_case_field", case_sensitive=False) == lower_field assert type_var.field_by_name("upper_case_field", case_sensitive=False) == upper_field From 31b9d9e51dddef483a88939d04ef42f206ed63d9 Mon Sep 17 00:00:00 2001 From: Anthony Lam Date: Mon, 9 Sep 2024 11:58:44 -0700 Subject: [PATCH 4/4] Fix formatting post-lint --- tests/test_types.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_types.py b/tests/test_types.py index fc67a214e6..b19df17e08 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -148,9 +148,10 @@ def test_struct_type() -> None: assert type_var != StructType(NestedField(1, "optional_field", IntegerType(), required=True)) assert type_var == pickle.loads(pickle.dumps(type_var)) + def test_struct_field_by_name() -> None: - lower_field = NestedField(1, "lower_case_field", IntegerType(), required=True), - upper_field = NestedField(2, "UPPER_CASE_FIELD", IntegerType(), required=True), + lower_field = NestedField(1, "lower_case_field", IntegerType(), required=True) + upper_field = NestedField(2, "UPPER_CASE_FIELD", IntegerType(), required=True) type_var = StructType(lower_field, upper_field) assert type_var.field_by_name("lower_case_field", case_sensitive=False) == lower_field @@ -161,6 +162,7 @@ def test_struct_field_by_name() -> None: assert type_var.field_by_name("upper_case_field", case_sensitive=True) is None assert type_var.field_by_name("nonexistent_field", case_sensitive=True) is None + def test_list_type() -> None: type_var = ListType( 1,