google/temporian

New Operator: `relative_distance`

Opened this issue · 0 comments

The operator should return the relative distance of the timestamps to a given input timestamp. This is especially useful to compute the distance to special days like public holidays. Example:

# Example 1
a = tp.event_set(timestamps=[1, 2, 4, 5, 7, 9])
a.relative_distance(6)
>>>indexes: []
features: [('relative_distance', int64)]
events:
     (6 events):
        timestamps: [1. 2. 4. 5. 7. 9.]
        'relative_distance': [-4 -3 -2 -1  1  2]

#Example 2
b = tp.event_set(timestamps=[1, 2, 4, 5, 6, 7, 9])
b.relative_distance(6)
>>>indexes: []
features: [('relative_distance, int64)]
events:
     (7 events):
        timestamps: [1. 2. 4. 5. 6. 7. 9.]
        'relative_distance': [-4 -3 -2 -1  0  1  2]