Skip to content

Commit 7c48350

Browse files
committed
move convert_str_to_bool to properties
1 parent 1dba055 commit 7c48350

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

pyiceberg/io/pyarrow.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@
177177
TimeType,
178178
UnknownType,
179179
UUIDType,
180-
strtobool,
181180
)
182181
from pyiceberg.utils.concurrent import ExecutorFactory
183182
from pyiceberg.utils.config import Config
184183
from pyiceberg.utils.datetime import millis_to_datetime
185184
from pyiceberg.utils.decimal import unscaled_to_decimal
186185
from pyiceberg.utils.deprecated import deprecation_message
187186
from pyiceberg.utils.properties import (
187+
convert_str_to_bool,
188188
filter_properties,
189189
get_first_property_value_with_tracking,
190190
properties_with_prefix,
@@ -428,12 +428,6 @@ def _initialize_fs(self, scheme: str, netloc: Optional[str] = None) -> FileSyste
428428
else:
429429
raise ValueError(f"Unrecognized filesystem type in URI: {scheme}")
430430

431-
def _convert_str_to_bool(self, value: Any) -> bool:
432-
"""Convert string or other value to boolean, handling string representations properly."""
433-
if isinstance(value, str):
434-
return strtobool(value)
435-
return bool(value)
436-
437431
def _resolve_s3_region(
438432
self, provided_region: Optional[str], resolve_region_override: Any, bucket: Optional[str]
439433
) -> Optional[str]:
@@ -451,7 +445,7 @@ def _resolve_s3_region(
451445
# Handle resolve_region_override conversion
452446
should_resolve_region = False
453447
if resolve_region_override is not None:
454-
should_resolve_region = self._convert_str_to_bool(resolve_region_override)
448+
should_resolve_region = convert_str_to_bool(resolve_region_override)
455449

456450
# If no region provided or explicit resolve requested, try to resolve from bucket
457451
if provided_region is None or should_resolve_region:
@@ -493,7 +487,7 @@ def get(*keys: str) -> str | None:
493487
S3_RESOLVE_REGION
494488
) # this feature is only available for S3. Use `get` here so it does not get passed down to the S3FileSystem constructor
495489
if force_virtual_addressing := get(S3_FORCE_VIRTUAL_ADDRESSING, "s3.force_virtual_addressing"):
496-
client_kwargs["force_virtual_addressing"] = self._convert_str_to_bool(force_virtual_addressing)
490+
client_kwargs["force_virtual_addressing"] = convert_str_to_bool(force_virtual_addressing)
497491
else:
498492
# For Alibaba OSS protocol, default to True
499493
client_kwargs["force_virtual_addressing"] = True
@@ -549,7 +543,7 @@ def get(*keys: str) -> str | None:
549543
client_kwargs["session_name"] = session_name
550544

551545
if force_virtual_addressing := get(S3_FORCE_VIRTUAL_ADDRESSING, "s3.force_virtual_addressing"):
552-
client_kwargs["force_virtual_addressing"] = self._convert_str_to_bool(force_virtual_addressing)
546+
client_kwargs["force_virtual_addressing"] = convert_str_to_bool(force_virtual_addressing)
553547
# Handle retry strategy special case
554548
if retry_strategy_impl := get(S3_RETRY_STRATEGY_IMPL, "s3.retry_strategy"):
555549
if retry_instance := _import_retry_strategy(retry_strategy_impl):

pyiceberg/utils/properties.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def property_as_bool(
6969
return default
7070

7171

72+
def convert_str_to_bool(value: Any) -> bool:
73+
"""Convert string or other value to boolean, handling string representations properly."""
74+
if isinstance(value, str):
75+
return strtobool(value)
76+
return bool(value)
77+
78+
7279
def get_first_property_value(
7380
properties: Properties,
7481
*property_names: str,

0 commit comments

Comments
 (0)