Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyiceberg/io/fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _s3(properties: Properties) -> AbstractFileSystem:
if request_timeout := properties.get(S3_REQUEST_TIMEOUT):
config_kwargs["read_timeout"] = float(request_timeout)

if _force_virtual_addressing := properties.get(S3_FORCE_VIRTUAL_ADDRESSING):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably more of these issues throughout the codebase. Ideally, we could make a full Properties class that could handle most of this for us (instead of properties just being a dict)

if property_as_bool(properties, S3_FORCE_VIRTUAL_ADDRESSING, False):
config_kwargs["s3"] = {"addressing_style": "virtual"}

if s3_anonymous := properties.get(S3_ANONYMOUS):
Expand Down
6 changes: 3 additions & 3 deletions pyiceberg/utils/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def property_as_float(


def property_as_bool(
properties: dict[str, str],
properties: Properties,
property_name: str,
default: bool,
) -> bool:
if value := properties.get(property_name):
if (value := properties.get(property_name)) not in (None, ""):
try:
return strtobool(value)
return strtobool(str(value))
except ValueError as e:
raise ValueError(f"Could not parse table property {property_name} to a boolean: {value}") from e
return default
Expand Down
17 changes: 14 additions & 3 deletions tests/io/test_fsspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,20 @@ def test_fsspec_s3_session_properties() -> None:
)


def test_fsspec_s3_session_properties_force_virtual_addressing() -> None:
@pytest.mark.parametrize(
("force_virtual_addressing", "config_kwargs"),
[
("true", {"s3": {"addressing_style": "virtual"}}),
("false", {}),
(True, {"s3": {"addressing_style": "virtual"}}),
(False, {}),
],
)
def test_fsspec_s3_session_properties_force_virtual_addressing(
force_virtual_addressing: str | bool, config_kwargs: Properties
) -> None:
session_properties: Properties = {
"s3.force-virtual-addressing": True,
"s3.force-virtual-addressing": force_virtual_addressing,
"s3.endpoint": "http://localhost:9000",
"s3.access-key-id": "admin",
"s3.secret-access-key": "password",
Expand All @@ -346,7 +357,7 @@ def test_fsspec_s3_session_properties_force_virtual_addressing() -> None:
"region_name": "us-east-1",
"aws_session_token": "s3.session-token",
},
config_kwargs={"s3": {"addressing_style": "virtual"}},
config_kwargs=config_kwargs,
)


Expand Down
17 changes: 13 additions & 4 deletions tests/utils/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,23 @@ def test_property_as_float_with_invalid_value() -> None:
assert "Could not parse table property some_float_prop to a float: invalid" in str(exc.value)


def test_property_as_bool() -> None:
@pytest.mark.parametrize(
("value", "expected"),
[
("True", True),
("False", False),
(True, True),
(False, False),
],
)
def test_property_as_bool(value: str | bool, expected: bool) -> None:
properties = {
"bool": "True",
"bool": value,
}

assert property_as_bool(properties, "bool", default=False) is True
assert property_as_bool(properties, "bool", default=not expected) is expected
assert property_as_bool(properties, "missing", default=False) is False
assert property_as_float(properties, "missing") is None
assert property_as_bool(properties, "missing", default=True) is True


def test_property_as_bool_with_invalid_value() -> None:
Expand Down