Guides
Data pipeline
Record a pandas pipeline and read how many rows and nulls went in and out of each step, and which files it read and wrote.
When your program has imported pandas, each call of your code that receives or returns a DataFrame or a Series has one more line per such value in ormaos tree: rows, columns, the dtype of each column and its nulls. The cells are never recorded. The example is data-pipeline: a monthly report from two CSV exports.
Record the pipeline#
ormaos run -- python pipeline.py$ ormaos run -- python pipeline.py
report.csv written: 4 regions
ormaos: r1 exit 0 in …: 1 Python process, 8 calls, 0 exceptions, 6 io
ormaos: not collected: io: reads of the 1 file opened at pipeline.py:11: opened for reading, and no `read` call by Python code was seen on a file of that name: if it was read, that was inside C code (a file that is iterated, `for line in f`, `csv.reader`) (+2 more)
ormaos: saved in .ormaos/r1, next: ormaos tree r1:c1How many rows and nulls went in and out of each step?#
$ ormaos tree r1 --depth 3
r1:c1 <module>() -> NoneType pipeline.py:1 … io 6 calls below: 1
r1:c2 main() -> NoneType pipeline.py:40 … io 6 calls below: 6
r1:c3 load_orders(path: pathlib.PosixPath) -> DataFrame[200x4] pipeline.py:10 … io 4
returned: 200 rows x 4 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 5 null
r1:c4 load_customers(path: pathlib.PosixPath) -> DataFrame[40x3] pipeline.py:14 … io 1
returned: 40 rows x 3 columns: customer_id string 0 null, name str 0 null, region str 0 null
r1:c5 drop_unpriced(orders: DataFrame[200x4]) -> DataFrame[195x4] pipeline.py:18 …
orders: 200 rows x 4 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 5 null
returned: 195 rows x 4 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 0 null
r1:c6 join_customers(orders: DataFrame[195x4], customers: DataFrame[40x3]) -> DataFrame[178x6] pipeline.py:27 …
orders: 195 rows x 4 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 0 null
customers: 40 rows x 3 columns: customer_id string 0 null, name str 0 null, region str 0 null
returned: 178 rows x 6 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 0 null, name str 0 null, region str 0 null
r1:c7 revenue_by_region(joined: DataFrame[178x6]) -> DataFrame[4x2] pipeline.py:31 …
joined: 178 rows x 6 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 0 null, name str 0 null, region str 0 null
returned: 4 rows x 2 columns: region str 0 null, amount float64 0 null
r1:c8 write_report(report: DataFrame[4x2], path: pathlib.PosixPath) -> NoneType pipeline.py:36 … io 1
report: 4 rows x 2 columns: region str 0 null, amount float64 0 null
next: ormaos exceptions r1Read the steps in order: load_orders returned 200 rows with 5 nulls in amount; drop_unpriced returned 195 rows and no nulls; join_customers received 195 orders and returned 178 rows. Whether 178 is the number the report should have is for you to decide; the tree says where the count changed.
One step at a time:
$ ormaos tree r1:c5
inside: r1:c1 <module> > r1:c2 main
r1:c5 drop_unpriced(orders: DataFrame[200x4]) -> DataFrame[195x4] pipeline.py:18 …
orders: 200 rows x 4 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 5 null
returned: 195 rows x 4 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 0 null
next: ormaos tree r1:c2 | ormaos exceptions r1:c5$ ormaos tree r1 --function join_customers
r1: 1 of the 8 calls matches --function join_customers (1 join_customers; 0 raised)
r1:c6 join_customers(orders: DataFrame[195x4], customers: DataFrame[40x3]) -> DataFrame[178x6] pipeline.py:27 …
orders: 195 rows x 4 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 0 null
customers: 40 rows x 3 columns: customer_id string 0 null, name str 0 null, region str 0 null
returned: 178 rows x 6 columns: order_id int64 0 null, customer_id string 0 null, placed str 0 null, amount float64 0 null, name str 0 null, region str 0 null
next: ormaos tree r1:c6 | ormaos tree r1 | ormaos exceptions r1Which files did it read and write?#
$ ormaos io r1 --kind file
r1: 6 io events (file 6), showing file
1x file open /sys/fs/cgroup/cpu.max (read) -> raised at pipeline.py:11 in load_orders [r1:i1]
1x file open /sys/fs/cgroup/cpu/cpu.cfs_quota_us (read) -> raised at pipeline.py:11 in load_orders [r1:i2]
1x file open /sys/fs/cgroup/cpu/cpu.cfs_period_us (read) -> raised at pipeline.py:11 in load_orders [r1:i3]
1x file open orders.csv (read) at pipeline.py:11 in load_orders [r1:i4]
1x file open customers.csv (read) at pipeline.py:15 in load_customers [r1:i5]
1x file open report.csv (write) at pipeline.py:37 in write_report [r1:i6]
next: ormaos io r1:i1 | ormaos io r1:i2 | ormaos io r1:c3 | ormaos exceptions r1The first three are files under /sys/fs/cgroup, opened by library code while load_orders read the CSV, at the line of your code that called it; the three opens raised. pandas reads a CSV inside C code, so only the open is seen; ormaos show says so in not collected.
After a change, where do the frames first differ?#
Record before and after, then ormaos diff r1 r2. Its data: section names, for each function and argument, the first call where the rows, columns, dtypes or nulls are not the same.
Notes for data code#
- Ormaos never imports pandas. It looks at a value only when your program has imported the library, and only at objects of exactly
DataFrameandSeries(not a subclass, not a frame inside a list or a dict, not a local variable). - Nulls are not counted in a frame of more than 1,000,000 cells, or after the counting has taken 2 seconds in one process; the shape and the dtypes are always there. See Limits.
- A column label that is text is recorded as a name. In a frame whose labels come from the data (a pivot), those labels are in the recording.