開発者ツールチェーンFoundryTSAPI リファレンスfunctions.dsl

注: 以下の翻訳の正確性は検証されていません。AIPを利用して英語版の原文から機械的に翻訳されたものです。

foundryts.functions.dsl

foundryts.functions.dsl(program, return_type=None, labels=None, before='nearest', internal='default', after='nearest')

1つ以上の入力時系列に DSL の式を適用して、新しい時系列を生成する関数を返します。

式は、入力時系列の各タイムスタンプに適用されます。入力時系列のいずれかに値がないタイムスタンプには、 指定された補間戦略が使用されます。利用可能な戦略の一覧については、 interpolate() を参照してください。

DSL の式は、単項、二項、または n 項のオペランドに適用できます。DSL のすべての演算は合成可能なため、 単純な式を組み合わせて複雑な式を作成できます。

↗ 時系列 DSL 構文の完全なリファレンスはこちらを参照してください。

  • パラメーター:
    • program (str) – ↗ 時系列 DSL リファレンスドキュメントの 構文を使用して、1つ以上の入力時系列に適用する式です。
    • return_type (Type , 任意) – (非推奨)変換された系列の値に使用するデータ型です。
    • labels (List [str ] , 任意) – 式内で各入力時系列を参照するための、順序付きのラベルのリストです(デフォルトは [‘a’, ‘b’, …, ‘aa’, ‘ab’, …])。
    • before (Union [str , List [str ] ] , 任意) – 系列の最初の点より前にある点を補間する戦略です。系列ごとの戦略をリストで指定できます。 interpolate() の有効な戦略を使用してください(デフォルトは NEAREST)。
    • internal (Union [str , List [str ] ] , 任意) – 既存の点の間にある点を補間する戦略です。系列ごとの戦略をリストで指定できます。 interpolate() の有効な戦略を使用してください(デフォルトは数値時系列では LINEAR、 列挙型時系列では PREVIOUS)。
    • after (Union [str , List [str ] ] , 任意) – 系列の最初の点より後にある点を補間する戦略です。系列ごとの戦略をリストで指定できます。 interpolate() の有効な戦略を使用してください(デフォルトは NEAREST)。
  • 戻り値: 1つ以上の時系列を受け取り、入力時系列に式を適用して、更新された 単一の時系列を返す関数です。
  • 戻り値の型: (FunctionNode) -> FunctionNode

データフレームのスキーマ

列名データ型説明
timestamppandas.Timestamp点のタイムスタンプ
valueUnion[float, str]点の値
関連項目

interpolate()、udf()

例

Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 >>> series_1 = F.points( ... (10, 6.0), ... (20, 11.0), ... (30, 24.0), ... (40, float("inf")), ... (50, 45.0), ... (60, 96.0), ... name="series-1", ... ) >>> series_2 = F.points( ... (10, 8.0), ... (20, 12.0), ... (30, 24.0), ... (40, 48.0), ... (50, float("NaN")), ... (60, 196.0), ... name="series-2", ... ) >>> series_1.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 6.0 1 1970-01-01 00:00:00.000000020 11.0 2 1970-01-01 00:00:00.000000030 24.0 3 1970-01-01 00:00:00.000000040 inf 4 1970-01-01 00:00:00.000000050 45.0 5 1970-01-01 00:00:00.000000060 96.0 >>> series_2.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 8.0 1 1970-01-01 00:00:00.000000020 12.0 2 1970-01-01 00:00:00.000000030 24.0 3 1970-01-01 00:00:00.000000040 48.0 4 1970-01-01 00:00:00.000000050 NaN 5 1970-01-01 00:00:00.000000060 196.0
Copied!
1 2 3 4 5 6 7 8 9 10 >>> sum_formula = "a+b" >>> sum_series = F.dsl(sum_formula)([series_1, series_2]) >>> sum_series.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 14.0 1 1970-01-01 00:00:00.000000020 23.0 2 1970-01-01 00:00:00.000000030 48.0 3 1970-01-01 00:00:00.000000040 inf 4 1970-01-01 00:00:00.000000050 NaN 5 1970-01-01 00:00:00.000000060 292.0
Copied!
1 2 3 4 5 6 7 >>> even_only_formula = "a % 2 == 0 ? a : skip" >>> even_series_1 = F.dsl(even_only_formula)(series_1) >>> even_series_1.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 6.0 1 1970-01-01 00:00:00.000000030 24.0 2 1970-01-01 00:00:00.000000060 96.0
Copied!
1 2 3 4 5 6 7 8 9 10 >>> argmin_formula = "argmin(a,b)" >>> argmin_series = F.dsl(argmin_formula)([series_1, series_2]) >>> argmin_series.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 0.0 1 1970-01-01 00:00:00.000000020 0.0 2 1970-01-01 00:00:00.000000030 0.0 3 1970-01-01 00:00:00.000000040 1.0 # inf は48より大きいです 4 1970-01-01 00:00:00.000000050 0.0 5 1970-01-01 00:00:00.000000060 0.0
Copied!
1 2 3 4 5 6 7 8 9 10 >>> pow_formula = "pow(a, 2)" >>> pow2_series = F.dsl(pow_formula)([series_1]) >>> pow2_series.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 36.0 1 1970-01-01 00:00:00.000000020 121.0 2 1970-01-01 00:00:00.000000030 576.0 3 1970-01-01 00:00:00.000000040 inf 4 1970-01-01 00:00:00.000000050 2025.0 5 1970-01-01 00:00:00.000000060 9216.0
Copied!
1 2 3 4 5 6 7 8 9 10 >>> non_nan_formula = "isnan(b) ? a : b" >>> non_nan_series = F.dsl(non_nan_formula)([series_1, series_2]) >>> non_nan_series.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 8.0 1 1970-01-01 00:00:00.000000020 12.0 2 1970-01-01 00:00:00.000000030 24.0 3 1970-01-01 00:00:00.000000040 48.0 4 1970-01-01 00:00:00.000000050 45.0 # series-1 の値のみ 5 1970-01-01 00:00:00.000000060 196.0
Copied!
1 2 3 4 5 6 7 8 9 10 >>> non_inf_formula = "isfinite(a) ? a : b" >>> non_inf_series = F.dsl(non_inf_formula)([series_1, series_2]) >>> non_inf_series.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 6.0 1 1970-01-01 00:00:00.000000020 11.0 2 1970-01-01 00:00:00.000000030 24.0 3 1970-01-01 00:00:00.000000040 48.0 # series-2 の値のみ 4 1970-01-01 00:00:00.000000050 45.0 5 1970-01-01 00:00:00.000000060 96.0
Copied!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 >>> assignment_formula = ''' ... var doubled_shifted = a * 2; // all values are doubled ... doubled_shifted += 10; // add 10 to all doubled values ... doubled_shifted - b // difference between double_shifted and b ... ''' >>> var_assigned_series = F.dsl(assignment_formula)([series_1, series_2]) >>> var_assigned_series.to_pandas() timestamp value 0 1970-01-01 00:00:00.000000010 14.0 1 1970-01-01 00:00:00.000000020 20.0 2 1970-01-01 00:00:00.000000030 34.0 3 1970-01-01 00:00:00.000000040 inf 4 1970-01-01 00:00:00.000000050 NaN 5 1970-01-01 00:00:00.000000060 6.0