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

Small example improvement using pyarrow assertion #669

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions examples/echo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ Make sure to have, dora, pip and cargo installed.
dora up
dora build dataflow.yml
dora start dataflow.yml

# In another terminal
terminal-input
```
24 changes: 13 additions & 11 deletions examples/echo/dataflow.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
nodes:
- id: terminal-input
build: pip install -e ../../node-hub/terminal-input
path: dynamic
- id: pyarrow-sender
build: pip install -e ../../node-hub/pyarrow-sender
path: pyarrow-sender
outputs:
- data
inputs:
echo: dora-echo/echo
env:
DATA: "[1, 2, 3, 4, 5]"

- id: dora-echo
build: pip install -e ../../node-hub/dora-echo
path: dora-echo
inputs:
echo: terminal-input/data
data: pyarrow-sender/data
outputs:
- echo
- data

- id: terminal-print
build: cargo build -p terminal-print
path: dynamic
- id: pyarrow-assert
build: pip install -e ../../node-hub/pyarrow-assert
path: pyarrow-assert
inputs:
echo: dora-echo/echo
data: dora-echo/data
env:
DATA: "[1, 2, 3, 4, 5]"
4 changes: 2 additions & 2 deletions examples/pyarrow-test/dataflow.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
nodes:
- id: pyarrow-sender
build: pip install -e ../../node-hub/pyarrow-sender
path: dynamic
path: pyarrow-sender
outputs:
- data
env:
Expand All @@ -13,4 +13,4 @@ nodes:
inputs:
data: pyarrow-sender/data
env:
DATA: "pa.array([1, 2, 3, 4, 5])"
DATA: "[1, 2, 3, 4, 5]"
17 changes: 14 additions & 3 deletions node-hub/pyarrow-assert/pyarrow_assert/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
import ast


import pyarrow as pa
from dora import Node

RUNNER_CI = True if os.getenv("CI") == "true" else False
Expand Down Expand Up @@ -36,12 +36,23 @@ def main():
args.name
) # provide the name to connect to the dataflow if dynamic node

assert_data = ast.literal_eval(data)
data = ast.literal_eval(data)

if isinstance(data, list):
data = pa.array(data) # initialize pyarrow array
elif isinstance(data, str):
data = pa.array([data])
elif isinstance(data, int):
data = pa.array([data])
elif isinstance(data, float):
data = pa.array([data])
else:
data = pa.array(data) # initialize pyarrow array

for event in node:
if event["type"] == "INPUT":
value = event["value"]
assert value == assert_data, f"Expected {assert_data}, got {value}"
assert value == data, f"Expected {data}, got {value}"


if __name__ == "__main__":
Expand Down
Loading