-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'flyteorg:master' into master
- Loading branch information
Showing
8 changed files
with
149 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ __pycache__/ | |
.idea | ||
.jpg | ||
.ipynb_checkpoints/ | ||
*.csv | ||
*.dat | ||
.DS_Store | ||
gen_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
examples/data_types_and_io/data_types_and_io/file_streaming.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
|
||
import pandas as pd | ||
from flytekit import task, workflow | ||
from flytekit.types.directory import FlyteDirectory | ||
from flytekit.types.file import FlyteFile | ||
|
||
|
||
@task() | ||
def remove_some_rows(ff: FlyteFile) -> FlyteFile: | ||
""" | ||
Remove the rows that the value of city is 'Seattle'. | ||
This is an example with streaming support. | ||
""" | ||
new_file = FlyteFile.new_remote_file("data_without_seattle.csv") | ||
with ff.open("r") as r: | ||
with new_file.open("w") as w: | ||
df = pd.read_csv(r) | ||
df = df[df["City"] != "Seattle"] | ||
df.to_csv(w, index=False) | ||
return new_file | ||
|
||
|
||
@task | ||
def process_folder(fd: FlyteDirectory) -> FlyteDirectory: | ||
out_fd = FlyteDirectory.new_remote("folder-copy") | ||
for base, x in fd.crawl(): | ||
src = str(os.path.join(base, x)) | ||
out_file = out_fd.new_file(x) | ||
with FlyteFile(src).open("rb") as f: | ||
with out_file.open("wb") as o: | ||
o.write(f.read()) | ||
# The output path will be s3://my-s3-bucket/data/77/<execution-id>-<node-id>-0/folder-copy | ||
return out_fd | ||
|
||
|
||
@workflow() | ||
def wf(): | ||
remove_some_rows(ff=FlyteFile("s3://custom-bucket/data.csv")) | ||
process_folder(fd=FlyteDirectory("s3://my-s3-bucket/folder")) | ||
return | ||
|
||
|
||
if __name__ == "__main__": | ||
print(f"Running wf() {wf()}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pandas | ||
torch | ||
tabulate | ||
tensorflow | ||
pyarrow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters