xgbtxy opened a new pull request, #4489: URL: https://github.com/apache/iceberg-python/pull/4489
# Rationale for this change `property_as_int()`, `property_as_float()`, and `get_first_property_value()` in `pyiceberg/utils/properties.py` checked truthiness (`if value := properties.get(...)`) rather than checking for `None` or `""`. Because `0`, `0.0`, and `False` are falsy in Python, passing an explicit numeric zero or boolean `False` via `Properties` (for example `commit.retry.num-retries=0`, `rest.sigv4-max-retries=0`, `write.parquet.compression-level=0`, or `residual-cache-max-size=0`) silently fell back to the default value or a later fallback key. This change aligns `property_as_int()`, `property_as_float()`, and `get_first_property_value()` with `property_as_bool()` (checking `is not None and ... != ""` so empty strings and `None` remain treated as unset while valid falsy values are honored, consistent with the discussion in #3713 / #3801 and `merge_config` in `pyiceberg/utils/config.py`). It also widens the `properties` parameter type of `property_as_int()` and `property_as_float()` from `dict[str, str]` to `Mapping[str, Any]` to match callers passing `Properties` (`dict[str, Any]`) or `dict[str, str]`. ## Are these changes tested? Yes. Added regression tests in `tests/utils/test_properties.py`: - `test_property_as_int_preserves_zero_and_treats_empty_as_unset` - `test_property_as_float_preserves_zero_and_treats_empty_as_unset` - `test_get_first_property_value_preserves_falsy_non_empty_values` Confirmed all 3 new tests fail prior to the fix (`3 failed`) and all 13 tests in `tests/utils/test_properties.py` pass after the fix (`13 passed`), along with `ruff`, `ty`, `mypy`, and `codespell` checks. ## Are there any user-facing changes? Yes. Passing explicit falsy non-empty property values (`0`, `0.0`, `False`) in `Properties` to `property_as_int()`, `property_as_float()`, or `get_first_property_value()` now preserves those values instead of silently falling back to defaults or secondary keys. Empty strings (`""`) and `None` continue to be treated as unset. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
