Skip to content

Commit ff76144

Browse files
authored
Clean up import in test_schema.py (#1858)
<!-- Thanks for opening a pull request! --> <!-- In the case this PR will resolve an issue, please replace ${GITHUB_ISSUE_ID} below with the actual Github issue id. --> <!-- Closes #${GITHUB_ISSUE_ID} --> # Rationale for this change Closed #1852 # Are these changes tested? N/A # Are there any user-facing changes? <!-- In the case of user-facing changes, please add the changelog label. -->
1 parent 7a56ddb commit ff76144

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tests/test_schema.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
import pyarrow as pa
2222
import pytest
2323

24-
from pyiceberg import schema
2524
from pyiceberg.exceptions import ResolveError, ValidationError
2625
from pyiceberg.schema import (
2726
Accessor,
2827
Schema,
2928
build_position_accessors,
29+
index_by_id,
30+
index_by_name,
3031
promote,
3132
prune_columns,
3233
sanitize_column_names,
@@ -90,15 +91,15 @@ def test_schema_str(table_schema_simple: Schema) -> None:
9091

9192
def test_schema_repr_single_field() -> None:
9293
"""Test schema representation"""
93-
actual = repr(schema.Schema(NestedField(field_id=1, name="foo", field_type=StringType()), schema_id=1))
94+
actual = repr(Schema(NestedField(field_id=1, name="foo", field_type=StringType()), schema_id=1))
9495
expected = "Schema(NestedField(field_id=1, name='foo', field_type=StringType(), required=False), schema_id=1, identifier_field_ids=[])"
9596
assert expected == actual
9697

9798

9899
def test_schema_repr_two_fields() -> None:
99100
"""Test schema representation"""
100101
actual = repr(
101-
schema.Schema(
102+
Schema(
102103
NestedField(field_id=1, name="foo", field_type=StringType()),
103104
NestedField(field_id=2, name="bar", field_type=IntegerType(), required=False),
104105
schema_id=1,
@@ -111,7 +112,7 @@ def test_schema_repr_two_fields() -> None:
111112
def test_schema_raise_on_duplicate_names() -> None:
112113
"""Test schema representation"""
113114
with pytest.raises(ValueError) as exc_info:
114-
schema.Schema(
115+
Schema(
115116
NestedField(field_id=1, name="foo", field_type=StringType(), required=False),
116117
NestedField(field_id=2, name="bar", field_type=IntegerType(), required=True),
117118
NestedField(field_id=3, name="baz", field_type=BooleanType(), required=False),
@@ -125,7 +126,7 @@ def test_schema_raise_on_duplicate_names() -> None:
125126

126127
def test_schema_index_by_id_visitor(table_schema_nested: Schema) -> None:
127128
"""Test index_by_id visitor function"""
128-
index = schema.index_by_id(table_schema_nested)
129+
index = index_by_id(table_schema_nested)
129130
assert index == {
130131
1: NestedField(field_id=1, name="foo", field_type=StringType(), required=False),
131132
2: NestedField(field_id=2, name="bar", field_type=IntegerType(), required=True),
@@ -198,7 +199,7 @@ def test_schema_index_by_id_visitor(table_schema_nested: Schema) -> None:
198199

199200
def test_schema_index_by_name_visitor(table_schema_nested: Schema) -> None:
200201
"""Test index_by_name visitor function"""
201-
table_schema_nested = schema.Schema(
202+
table_schema_nested = Schema(
202203
NestedField(field_id=1, name="foo", field_type=StringType(), required=False),
203204
NestedField(field_id=2, name="bar", field_type=IntegerType(), required=True),
204205
NestedField(field_id=3, name="baz", field_type=BooleanType(), required=False),
@@ -245,7 +246,7 @@ def test_schema_index_by_name_visitor(table_schema_nested: Schema) -> None:
245246
schema_id=1,
246247
identifier_field_ids=[2],
247248
)
248-
index = schema.index_by_name(table_schema_nested)
249+
index = index_by_name(table_schema_nested)
249250
assert index == {
250251
"foo": 1,
251252
"bar": 2,
@@ -301,7 +302,7 @@ def test_schema_find_column_name_by_id(table_schema_simple: Schema) -> None:
301302

302303
def test_schema_find_field_by_id(table_schema_simple: Schema) -> None:
303304
"""Test finding a column using its field ID"""
304-
index = schema.index_by_id(table_schema_simple)
305+
index = index_by_id(table_schema_simple)
305306

306307
column1 = index[1]
307308
assert isinstance(column1, NestedField)
@@ -324,15 +325,15 @@ def test_schema_find_field_by_id(table_schema_simple: Schema) -> None:
324325

325326
def test_schema_find_field_by_id_raise_on_unknown_field(table_schema_simple: Schema) -> None:
326327
"""Test raising when the field ID is not found among columns"""
327-
index = schema.index_by_id(table_schema_simple)
328+
index = index_by_id(table_schema_simple)
328329
with pytest.raises(Exception) as exc_info:
329330
_ = index[4]
330331
assert str(exc_info.value) == "4"
331332

332333

333334
def test_schema_find_field_type_by_id(table_schema_simple: Schema) -> None:
334335
"""Test retrieving a columns' type using its field ID"""
335-
index = schema.index_by_id(table_schema_simple)
336+
index = index_by_id(table_schema_simple)
336337
assert index[1] == NestedField(field_id=1, name="foo", field_type=StringType(), required=False)
337338
assert index[2] == NestedField(field_id=2, name="bar", field_type=IntegerType(), required=True)
338339
assert index[3] == NestedField(field_id=3, name="baz", field_type=BooleanType(), required=False)
@@ -341,7 +342,7 @@ def test_schema_find_field_type_by_id(table_schema_simple: Schema) -> None:
341342
def test_index_by_id_schema_visitor_raise_on_unregistered_type() -> None:
342343
"""Test raising a NotImplementedError when an invalid type is provided to the index_by_id function"""
343344
with pytest.raises(NotImplementedError) as exc_info:
344-
schema.index_by_id("foo") # type: ignore
345+
index_by_id("foo") # type: ignore
345346
assert "Cannot visit non-type: foo" in str(exc_info.value)
346347

347348

0 commit comments

Comments
 (0)