Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CODE WIDE] Operator chaining #206

Merged
merged 28 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7273776
first attempt at chaining
ianspektor Jul 19, 2023
a030d4e
fix
ianspektor Jul 19, 2023
edf8207
tests
ianspektor Jul 19, 2023
5b659e7
bump mkdocstrings-python version, fix links to EventSet.op
ianspektor Jul 20, 2023
9172d07
hide bases
ianspektor Jul 21, 2023
ba484b5
rename mixin to EventSetOperations
ianspektor Jul 21, 2023
9c510ae
add_index and set_index
ianspektor Jul 21, 2023
e6eaeee
cast
ianspektor Jul 21, 2023
49cf24a
Merge branch 'main' into op-chaining
ianspektor Jul 21, 2023
dc7c2e9
drop_index, end, enumerate
ianspektor Jul 21, 2023
8515f37
filter
ianspektor Jul 21, 2023
a90067d
join
ianspektor Jul 21, 2023
e921d1f
lag and leak
ianspektor Jul 21, 2023
10326a3
prefix
ianspektor Jul 21, 2023
505f31a
propagate
ianspektor Jul 21, 2023
ac54d56
rename, resample
ianspektor Jul 21, 2023
f70eb1b
select, since_last, tick
ianspektor Jul 21, 2023
503bce5
timestamps, unique_timestamps, fix docs
ianspektor Jul 21, 2023
53db603
calendar ops
ianspektor Jul 21, 2023
77af593
window ops
ianspektor Jul 21, 2023
1b30a52
improve docs
ianspektor Jul 21, 2023
10d3f9b
Merge branch 'main' into op-chaining
ianspektor Jul 24, 2023
254c3ec
update fraud and gettingstarted nbs
ianspektor Jul 24, 2023
1d92bad
update remaining nbs and user guide
ianspektor Jul 24, 2023
8ca6b88
update notebooks markdown to chaining
ianspektor Jul 24, 2023
77ec4e6
Run bank fraud and m5 notebooks with chained-ops
DonBraulio Jul 24, 2023
ffa8a2c
clean bazel deps
ianspektor Jul 24, 2023
87298a7
run remaining notebooks
ianspektor Jul 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ input_data = tp.from_csv("sales.csv")
# Define a Temporian program
input_node = input_data.node()
per_store = tp.set_index(input_node, "store")
weekly_sum = tp.moving_sum(per_store["price"], window_length=tp.duration.days(7))
weekly_sum = per_store["price"].moving_sum(window_length=tp.duration.days(7))

# Execute Temporian program
output_data = weekly_sum.run({input_node: input_data})
Expand Down
15 changes: 7 additions & 8 deletions benchmark/benchmark_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def benchmark_simple_moving_average(runner):
ds = _build_toy_dataset(n)

node = ds.node()
output = tp.simple_moving_average(node, window_length=10.0)
output = node.simple_moving_average(window_length=10.0)

runner.benchmark(
f"simple_moving_average:{n:_}",
Expand Down Expand Up @@ -114,7 +114,7 @@ def benchmark_calendar_day_of_month(runner):
ds = tp.from_pandas(pd.DataFrame({"timestamp": timestamps}))

node = ds.node()
output = tp.calendar_day_of_month(node)
output = node.calendar_day_of_month()

runner.benchmark(
f"calendar_day_of_month:{n:_}",
Expand All @@ -131,7 +131,7 @@ def benchmark_sample(runner):

node_1 = ds_1.node()
node_2 = ds_2.node()
output = tp.resample(node_1, node_2)
output = node_1.resample(node_2)

runner.benchmark(
f"sample:e{m:_}_s{n:_}",
Expand All @@ -144,7 +144,7 @@ def benchmark_propagate(runner):
for n in [100, 10_000, 1_000_000]:
ds = _build_toy_dataset(n, data2_is_categorical_integer=True)
node = ds.node()
output = tp.propagate(node["data_1"], node["data_2"])
output = node["data_1"].propagate(node["data_2"])

runner.benchmark(
f"propagate:{n:_}",
Expand All @@ -159,8 +159,7 @@ def benchmark_cast(runner):
ds = _build_toy_dataset(n)

node = ds.node()
output = tp.cast(
node,
output = node.cast(
{
"data_1": tp.int32,
"data_2": tp.float32,
Expand All @@ -179,7 +178,7 @@ def benchmark_unique_timestamps(runner):
for n in [100, 10_000, 1_000_000]:
ds = _build_toy_dataset(n, data2_is_categorical_integer=True)
node = ds.node()
output = tp.unique_timestamps(node["data_1"])
output = node["data_1"].unique_timestamps()

runner.benchmark(
f"unique_timestamps:{n}",
Expand Down Expand Up @@ -279,7 +278,7 @@ def benchmark_add_index(runner):
]

for index in possible_indexes:
output = tp.add_index(node, index)
output = node.add_index(index)
runner.benchmark(
f"add_index:s:{number_timestamps:_}:num_idx:{len(index)}",
lambda: tp.run(output, input={node: evset}),
Expand Down
2 changes: 1 addition & 1 deletion benchmark/scripts/add_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def main():
indexes = ["feature_1", "feature_2", "feature_3", "feature_4", "feature_5"]

input_node = input_data.node()
output_node = tp.add_index(input_node, indexes)
output_node = input_node.add_index(indexes)

run(input_node, input_data, output_node)

Expand Down
4 changes: 2 additions & 2 deletions benchmark/scripts/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def main():
node_2._sampling = node_1._sampling

a = tp.glue(node_1, node_2)
b = tp.prefix(tp.simple_moving_average(a, window_length=10.0), "sma_")
c = tp.glue(a, tp.resample(b, a))
b = a.simple_moving_average(window_length=10.0).prefix("sma_")
c = tp.glue(a, b.resample(a))

res: EventSet = tp.run(
c,
Expand Down
2 changes: 1 addition & 1 deletion benchmark/scripts/sma.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main():

node = evset.node()

sma = tp.simple_moving_average(node, window_length=10)
sma = node.simple_moving_average(window_length=10)

res: EventSet = tp.run(
sma,
Expand Down
7 changes: 5 additions & 2 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,20 @@ plugins:
# https://mkdocstrings.github.io/python/usage/#globallocal-options
docstring_style: google
heading_level: 1
members_order: source
members_order: alphabetical
show_source: false
show_submodules: false
merge_init_into_class: false
show_signature: true
separate_signature: true
show_signature_annotations: true
separate_signature: true
show_if_no_docstring: false
group_by_category: true
show_category_heading: false
show_root_heading: true
inherited_members: true
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did it worked?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It did :) the option literally got released last week in https://github.com/mkdocstrings/python/releases/tag/1.2.0

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what it's called being lucky :)

show_bases: false
# show_root_full_path: false
# show_root_toc_entry: false
# show_symbol_type_heading: false
# preload_modules: [temporian.core.operators]
Expand Down
38 changes: 0 additions & 38 deletions docs/public_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,7 @@
"save_graph",
"load_graph",
# OPERATORS
"cast",
"drop_index",
"enumerate",
"filter",
"glue",
"join",
"add_index",
"set_index",
"lag",
"leak",
"prefix",
"propagate",
"resample",
"select",
"rename",
"since_last",
"begin",
"end",
"tick",
"timestamps",
"unique_timestamps",
# BINARY OPERATORS
"add",
"subtract",
Expand All @@ -88,16 +68,6 @@
"logical_and",
"logical_or",
"logical_xor",
# CALENDAR OPERATORS
"calendar_day_of_month",
"calendar_day_of_week",
"calendar_day_of_year",
"calendar_hour",
"calendar_iso_week",
"calendar_minute",
"calendar_month",
"calendar_second",
"calendar_year",
# SCALAR OPERATORS
"add_scalar",
"subtract_scalar",
Expand All @@ -118,14 +88,6 @@
"invert",
"isnan",
"notnan",
# WINDOW OPERATORS
"simple_moving_average",
"moving_standard_deviation",
"cumsum",
"moving_sum",
"moving_count",
"moving_min",
"moving_max",
}


Expand Down
6 changes: 3 additions & 3 deletions docs/src/3_minutes.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ If the [`EventSet`][temporian.EventSet] has one (or many) indexes, its events wi

## Operators

Processing operations are performed by **operators**. For instance, the `tp.simple_moving_average()` operator computes the [simple moving average](https://en.wikipedia.org/wiki/Moving_average) of each feature in an [`EventSet`][temporian.EventSet].
Processing operations are performed by **operators**. For instance, the [`EventSet.simple_moving_average()`][temporian.EventSet.simple_moving_average] operator computes the [simple moving average](https://en.wikipedia.org/wiki/Moving_average) of each feature in an [`EventSet`][temporian.EventSet].

The list of all available operators is available in the [API Reference](./reference/).

```python
>>> # Compute the 2-day simple moving average of the EventSet defined above
>>> sma = tp.simple_moving_average(evset, window_length=tp.duration.days(2))
>>> sma = evset.simple_moving_average(window_length=tp.duration.days(2))

>>> # Remove index to get a flat EventSet
>>> reindexed = tp.drop_index(sma)
>>> reindexed = sma.drop_index()

>>> # Subtract feature_1 from feature_3
>>> sub = reindexed["feature_3"] - reindexed["feature_1"]
Expand Down
Loading