Skip to content

Prevent Errors on Empty or Non-Shortenable Inputs in Truncation #327

@LakminiSenanayake

Description

@LakminiSenanayake

The original balanced_truncate function is not handling certain edge cases gracefully, leading to unintended behavior. Specifically:
- If any entry in input_dict['shortenable_ids'] was an empty list, the code could raise an IndexError when accessing parts[0].
- If total_shortenable_len was zero (e.g. no shortenable parts), a division by zero would occur during proportional calculation.
- Truncation lengths were not capped properly, which could result in slicing with negative indices.
- The function retained empty sequences post-truncation, which might be undesirable in downstream tasks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions