MCPcopy Index your code
hub / github.com/pathwaycom/pathway / interpolate

Function interpolate

python/pathway/stdlib/statistical/_interpolate.py:56–167  ·  view source on GitHub ↗

Interpolates missing values in a column using the previous and next values based on a timestamps column. Args: timestamp (ColumnReference): Reference to the column containing timestamps. *values (ColumnReference): References to the columns containing values to be interpolat

(
    self: pw.Table,
    timestamp: pw.ColumnReference,
    *values: pw.ColumnReference,
    mode: InterpolateMode = InterpolateMode.LINEAR,
)

Source from the content-addressed store, hash-verified

54
55@trace_user_frame
56def interpolate(
57 self: pw.Table,
58 timestamp: pw.ColumnReference,
59 *values: pw.ColumnReference,
60 mode: InterpolateMode = InterpolateMode.LINEAR,
61):
62 """
63 Interpolates missing values in a column using the previous and next values based on a timestamps column.
64
65 Args:
66 timestamp (ColumnReference): Reference to the column containing timestamps.
67 *values (ColumnReference): References to the columns containing values to be interpolated.
68 mode (InterpolateMode, optional): The interpolation mode. Currently,\
69 only InterpolateMode.LINEAR is supported. Default is InterpolateMode.LINEAR.
70
71 Returns:
72 Table: A new table with the interpolated values.
73
74 Raises:
75 ValueError: If the columns are not ColumnReference or if the interpolation mode is not supported.
76
77 Note:
78 - The interpolation is performed based on linear interpolation between the previous and next values.
79 - If a value is missing at the beginning or end of the column, no interpolation is performed.
80
81 Example:
82
83 >>> import pathway as pw
84 >>> table = pw.debug.table_from_markdown('''
85 ... timestamp | values_a | values_b
86 ... 1 | 1 | 10
87 ... 2 | |
88 ... 3 | 3 |
89 ... 4 | |
90 ... 5 | |
91 ... 6 | 6 | 60
92 ... ''')
93 >>> table = table.interpolate(pw.this.timestamp, pw.this.values_a, pw.this.values_b)
94 >>> pw.debug.compute_and_print(table, include_id=False)
95 timestamp | values_a | values_b
96 1 | 1.0 | 10.0
97 2 | 2.0 | 20.0
98 3 | 3.0 | 30.0
99 4 | 4.0 | 40.0
100 5 | 5.0 | 50.0
101 6 | 6.0 | 60.0
102 """
103
104 if mode != InterpolateMode.LINEAR:
105 raise ValueError(
106 """interpolate: Invalid mode. Only Interpolate.LINEAR is currently available."""
107 )
108
109 if isinstance(timestamp, pw.ColumnReference):
110 timestamp = self[timestamp]
111 else:
112 if isinstance(timestamp, str):
113 raise ValueError(

Callers

nothing calls this directly

Calls 6

_linear_interpolateFunction · 0.85
sortMethod · 0.80
with_columnsMethod · 0.80
selectMethod · 0.45
ixMethod · 0.45

Tested by

no test coverage detected