Skip to content

Commit

Permalink
rewrite validator
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinjqliu committed Mar 8, 2024
1 parent 5616ef0 commit 9fe9cff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
6 changes: 4 additions & 2 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,10 @@ class SetLocationUpdate(TableUpdate):
class SetPropertiesUpdate(TableUpdate):
action: TableUpdateAction = TableUpdateAction.set_properties
updates: Properties
# validators
transform_properties_dict_value_to_str = field_validator('updates', mode='before')(transform_dict_value_to_str)

@field_validator('updates', mode='before')
def transform_properties_dict_value_to_str(cls, properties: Properties) -> Dict[str, str]:
return transform_dict_value_to_str(properties)


class RemovePropertiesUpdate(TableUpdate):
Expand Down
32 changes: 0 additions & 32 deletions tests/integration/test_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,38 +169,6 @@ def test_table_properties_error(catalog: Catalog) -> None:
assert "Cannot pass both properties and kwargs" in str(e.value)


@pytest.mark.integration
@pytest.mark.parametrize('catalog', [pytest.lazy_fixture('catalog_hive'), pytest.lazy_fixture('catalog_rest')])
def test_table_properties_dict(catalog: Catalog) -> None:
table = create_table(catalog)

assert table.properties == DEFAULT_PROPERTIES

with table.transaction() as transaction:
transaction.set_properties({"abc": "🤪"})
assert table.properties == dict({"abc": "🤪"}, **DEFAULT_PROPERTIES)

with table.transaction() as transaction:
transaction.remove_properties("abc")
assert table.properties == DEFAULT_PROPERTIES

table = table.transaction().set_properties({"abc": "def"}).commit_transaction()
assert table.properties == dict({"abc": "def"}, **DEFAULT_PROPERTIES)

table = table.transaction().remove_properties("abc").commit_transaction()
assert table.properties == DEFAULT_PROPERTIES


@pytest.mark.integration
@pytest.mark.parametrize('catalog', [pytest.lazy_fixture('catalog_hive'), pytest.lazy_fixture('catalog_rest')])
def test_table_properties_error(catalog: Catalog) -> None:
table = create_table(catalog)
properties = {"abc": "def"}
with pytest.raises(ValueError) as e:
table.transaction().set_properties(properties, abc="def").commit_transaction()
assert "Cannot pass both properties and kwargs" in str(e.value)


@pytest.mark.integration
@pytest.mark.parametrize('catalog', [pytest.lazy_fixture('catalog_hive'), pytest.lazy_fixture('catalog_rest')])
def test_pyarrow_nan(catalog: Catalog) -> None:
Expand Down

0 comments on commit 9fe9cff

Please sign in to comment.