From 3fffa072517e6fbabcfa78e4f9ef9a3988b0a5bc Mon Sep 17 00:00:00 2001 From: David F Little Date: Thu, 6 Oct 2022 16:50:37 +0000 Subject: [PATCH 1/2] mention workaround in README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index e4405b4..3527b01 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,9 @@ Rows match in this join if their time spans overlap. The time spans can be repre - [`Interval`](https://juliapackages.com/p/intervals) objects. - `NamedTuples` with a `start` and `stop` field. +[This is a workaround](https://github.com/beacon-biosignals/DataFrameIntervals.jl/pull/13) to support additional types, but the long-term goal is to implement support in `Interval` +that allows for generic support for any interval-like type. + ## Example ```julia From 55feaffcacb6f9df3e6713d253afd37d06dc7944 Mon Sep 17 00:00:00 2001 From: David Little Date: Mon, 17 Oct 2022 11:52:13 -0400 Subject: [PATCH 2/2] Update README.md Co-authored-by: Eric Hanson <5846501+ericphanson@users.noreply.github.com> --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3527b01..342f5a4 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,20 @@ Rows match in this join if their time spans overlap. The time spans can be repre - [`Interval`](https://juliapackages.com/p/intervals) objects. - `NamedTuples` with a `start` and `stop` field. -[This is a workaround](https://github.com/beacon-biosignals/DataFrameIntervals.jl/pull/13) to support additional types, but the long-term goal is to implement support in `Interval` -that allows for generic support for any interval-like type. +There are several options to support additional types, such as AlignedSpans. One option is to add interface methods to support automatic conversions to intervals; see e.g. [#13](https://github.com/beacon-biosignals/DataFrameIntervals.jl/pull/13). Another option is to manually convert to a supported type; this can provide additional control over how the conversion takes place. For example, one can simply convert to `TimeSpan`s: +```julia +timespanify = :span => ByRow(TimeSpan) => :span +interval_join(transform(df1, timespanify), transform(df2, timespanify); on=:span) +``` +For AlignedSpans, we can convert to integer indices, after checking the sample rates are all equal: +```julia +using Compat # for allequal +if !allequal(Iterators.flatten(((as.sample_rate for as in df1.span), (as.sample_rate for as in df2.span)))) + throw(ArgumentError("Sampling rates do not all match!")) +end +integer_spanify = :span => ByRow(as -> Interval{Int, Closed, Closed}(as.first_index, as.last_index)) => :span +interval_join(transform(df1, integer_spanify), transform(df2, integer_spanify); on=:span) +``` ## Example