diff --git a/crates/polars-io/src/cloud/polars_object_store.rs b/crates/polars-io/src/cloud/polars_object_store.rs index ceb82488fa09..0453ab65f22b 100644 --- a/crates/polars-io/src/cloud/polars_object_store.rs +++ b/crates/polars-io/src/cloud/polars_object_store.rs @@ -319,12 +319,12 @@ fn merge_ranges(ranges: &[Range]) -> impl Iterator, }; let should_merge = is_overlapping || { - let leq_existing_chunk_size_dist = new_merged.len().abs_diff(chunk_size) + let leq_current_dist_to_chunk_size = new_merged.len().abs_diff(chunk_size) <= current_merged_range.len().abs_diff(chunk_size); let gap_tolerance = (current_n_bytes.max(range.len()) / 8).clamp(1024 * 1024, 8 * 1024 * 1024); - leq_existing_chunk_size_dist && distance <= gap_tolerance + leq_current_dist_to_chunk_size && distance <= gap_tolerance }; if should_merge {