Skip to content

Add sort before groupby#31

Open
denini08 wants to merge 1 commit intoToilal:developfrom
denini08:develop
Open

Add sort before groupby#31
denini08 wants to merge 1 commit intoToilal:developfrom
denini08:develop

Conversation

@denini08
Copy link
Copy Markdown

@denini08 denini08 commented Jan 24, 2026

Hello!

While reading the code and running some tests, I noticed a small detail that could cause unexpected behavior when the input list is not ordered. The itertools.groupby() function assumes the data is already sorted by the key (docs), but in _group_by_match_index this was not guaranteed.

So I added a sorted() call before the groupby() to make the behavior safe and consistent, regardless of the input order.

Interestingly, the rest of the codebase already follows this same pattern:

I also added a small test that explicitly checks the behavior with unsorted input data, just to make sure this case is always covered.

Thank youfor the project!
I hope this improvement is helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant