Skip to content

fix(merge_neighbors): support non-numeric endpoints - #156

Open
IMGillusion wants to merge 1 commit into
chaimleib:masterfrom
IMGillusion:fix/115/merge-neighbors-non-numeric
Open

IMGillusion wants to merge 1 commit into
chaimleib:masterfrom
IMGillusion:fix/115/merge-neighbors-non-numeric

Conversation

@IMGillusion

Copy link
Copy Markdown

merge_neighbors() raised TypeError on non-numeric interval endpoints (e.g. datetime):

TypeError: '<=" not supported between instances of "datetime.timedelta" and "int"

because the default distance was the int 1, and the strict overlap check compared margin against the int 0.

This PR makes both defaults type-aware, inferred from the interval endpoints:

  • distance=None (new default) becomes 1 for numeric endpoints (the historical default) or the zero of the endpoint type (e.g. timedelta(0) for datetime), so only touching or overlapping intervals are merged.
  • the strict check compares margin against that same zero instead of the int 0.

An explicit distance of the endpoint type (e.g. timedelta(hours=3)) already worked before and still works.

Fixes #115

merge_neighbors() raised TypeError on non-numeric interval
endpoints (e.g. datetime) because the default distance was the
int 1 and the strict check compared margin against the int 0.

The default distance is now inferred from the endpoint type:
1 for numeric endpoints (the historical default), or the zero
of the endpoint type (e.g. timedelta(0) for datetime) so that
only touching or overlapping intervals are merged.

Fixes chaimleib#115
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.

merge_neighbors() does not work with datetime objects

1 participant