foundryts.functions.time_shift¶
foundryts.functions.time_shift(duration)¶
Returns a function that shifts all timestamps of a single time series forward or backward in time by the specified duration.
For a source time series with points (timestamp, value), upon shifting by duration,
the resulting time-shifted time series will have points (timestamp + duration, value).
Positive duration shift values will move the timestamps forward into the future and negative duration
values will move the timestamps backwards into the past.
- Parameters: duration (int , datetime.timedelta , str) – The amount of time to shift the timestamps forward or backward, specified as an integer, a datetime.timedelta object, or a string. Integers are interpreted as the number of nanoseconds. For more human-readable durations, you can provide a datetime.timedelta object or a string that will be parsed as a pandas.Timedelta. String inputs should follow the format recognized by pandas.to_timedelta, such as ‘1 day’, ‘1 hour’, ‘10 minutes’, or ’42s’.
- Returns: A function that accepts a single time series as input and returns the time-shifted time series.
- Return type:
(
FunctionNode) ->FunctionNode
Dataframe schema¶
| Column name | Type | Description |
|---|---|---|
| timestamp | pandas.Timestamp | Shifted Timestamp of the point |
| value | float | str |
:::callout{theme="success" title="See Also"}
timestamp_scale(), value_shift()
:::
Examples¶
>>> series = F.points(
... (100, 0.0),
... (200, float("inf")),
... (300, 3.14159),
... (2147483647, 1.0),
... name="series"
... )
>>> series.to_pandas()
timestamp value
0 1970-01-01 00:00:00.000000100 0.00000
1 1970-01-01 00:00:00.000000200 inf
2 1970-01-01 00:00:00.000000300 3.14159
3 1970-01-01 00:00:02.147483647 1.00000
>>> time_shifted = F.time_shift(1000)(series)
>>> time_shifted.to_pandas()
timestamp value
0 1970-01-01 00:00:00.000001100 0.00000
1 1970-01-01 00:00:00.000001200 inf
2 1970-01-01 00:00:00.000001300 3.14159
3 1970-01-01 00:00:02.147484647 1.00000
中文翻译¶
foundryts.functions.time_shift¶
foundryts.functions.time_shift(duration)¶
返回一个函数,该函数将单个时间序列(time series)中的所有时间戳按指定时长向前或向后平移。
对于源时间序列中的点 (timestamp, value),在按 duration 平移后,生成的时间平移时间序列将包含点 (timestamp + duration, value)。正数的 duration 平移值会将时间戳向前推移至未来,负数的 duration 值则会将时间戳向后推移至过去。
- 参数: duration(int,datetime.timedelta,str)– 将时间戳向前或向后平移的时间量,可指定为整数、datetime.timedelta 对象或字符串。整数被解释为纳秒数。如需更易读的时长表示,可提供 datetime.timedelta 对象或将被解析为 pandas.Timedelta 的字符串。字符串输入应遵循 pandas.to_timedelta 识别的格式,例如 '1 day'、'1 hour'、'10 minutes' 或 '42s'。
- 返回: 一个接受单个时间序列作为输入并返回时间平移后时间序列的函数。
- 返回类型:
(
FunctionNode) ->FunctionNode
数据框模式(Dataframe schema)¶
| 列名 | 类型 | 描述 |
|---|---|---|
| timestamp | pandas.Timestamp | 平移后的点的时间戳 |
| value | float | str | 点的值 |
:::callout{theme="success" title="另请参阅"}
timestamp_scale(),value_shift()
:::
示例¶
>>> series = F.points(
... (100, 0.0),
... (200, float("inf")),
... (300, 3.14159),
... (2147483647, 1.0),
... name="series"
... )
>>> series.to_pandas()
timestamp value
0 1970-01-01 00:00:00.000000100 0.00000
1 1970-01-01 00:00:00.000000200 inf
2 1970-01-01 00:00:00.000000300 3.14159
3 1970-01-01 00:00:02.147483647 1.00000
>>> time_shifted = F.time_shift(1000)(series)
>>> time_shifted.to_pandas()
timestamp value
0 1970-01-01 00:00:00.000001100 0.00000
1 1970-01-01 00:00:00.000001200 inf
2 1970-01-01 00:00:00.000001300 3.14159
3 1970-01-01 00:00:02.147484647 1.00000