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

Updating polars kwargs for scan/read_csv and LazyFrame operations #44

Merged
merged 2 commits into from
Apr 28, 2023
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
2 changes: 1 addition & 1 deletion polars_queries/q2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def q():
reverse=[True, False, False, False],
)
.limit(100)
.with_column(pl.col(pl.datatypes.Utf8).str.strip().keep_name())
.with_columns(pl.col(pl.datatypes.Utf8).str.strip().keep_name())
)

utils.run_query(Q_NUM, q_final)
Expand Down
2 changes: 1 addition & 1 deletion polars_queries/q3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def q():
.join(line_item_ds, left_on="o_orderkey", right_on="l_orderkey")
.filter(pl.col("o_orderdate") < var2)
.filter(pl.col("l_shipdate") > var1)
.with_column(
.with_columns(
(pl.col("l_extendedprice") * (1 - pl.col("l_discount"))).alias("revenue")
)
.groupby(["o_orderkey", "o_orderdate", "o_shippriority"])
Expand Down
2 changes: 1 addition & 1 deletion polars_queries/q4.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def q():
.groupby("o_orderpriority")
.agg(pl.count().alias("order_count"))
.sort(by="o_orderpriority")
.with_column(pl.col("order_count").cast(pl.datatypes.Int64))
.with_columns(pl.col("order_count").cast(pl.datatypes.Int64))
)

utils.run_query(Q_NUM, q_final)
Expand Down
2 changes: 1 addition & 1 deletion polars_queries/q5.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def q():
.filter(pl.col("r_name") == var1)
.filter(pl.col("o_orderdate") >= var2)
.filter(pl.col("o_orderdate") < var3)
.with_column(
.with_columns(
(pl.col("l_extendedprice") * (1 - pl.col("l_discount"))).alias("revenue")
)
.groupby("n_name")
Expand Down
4 changes: 2 additions & 2 deletions polars_queries/q7.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ def q():
pl.concat([df1, df2])
.filter(pl.col("l_shipdate") >= datetime(1995, 1, 1))
.filter(pl.col("l_shipdate") <= datetime(1996, 12, 31))
.with_column(
.with_columns(
(pl.col("l_extendedprice") * (1 - pl.col("l_discount"))).alias("volume")
)
.with_column(pl.col("l_shipdate").dt.year().alias("l_year"))
.with_columns(pl.col("l_shipdate").dt.year().alias("l_year"))
.groupby(["supp_nation", "cust_nation", "l_year"])
.agg([pl.sum("volume").alias("revenue")])
.sort(by=["supp_nation", "cust_nation", "l_year"])
Expand Down
2 changes: 1 addition & 1 deletion polars_queries/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _scan_ds(path: str):

def get_query_answer(query: int, base_dir: str = ANSWERS_BASE_DIR) -> pl.LazyFrame:
answer_ldf = pl.scan_csv(
join(base_dir, f"q{query}.out"), sep="|", has_header=True, parse_dates=True
join(base_dir, f"q{query}.out"), separator="|", has_header=True, try_parse_dates=True
)
cols = answer_ldf.columns
answer_ldf = answer_ldf.select(
Expand Down
4 changes: 2 additions & 2 deletions prepare_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@
df = pl.read_csv(
f"tables_scale_{scale_fac}/{name}.tbl",
has_header=False,
sep="|",
parse_dates=True,
separator="|",
try_parse_dates=True,
new_columns=eval(f"h_{name}"),
)
print(df.shape)
Expand Down
4 changes: 2 additions & 2 deletions prepare_large_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
df = pl.scan_csv(
f"tables_scale_{scale_fac}/{name}.tbl",
has_header=False,
sep="|",
parse_dates=True,
separator="|",
try_parse_dates=True,
with_column_names= lambda _: eval(f"h_{name}")
)

Expand Down
4 changes: 2 additions & 2 deletions scripts/plot_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def add_annotations(fig, limit: int, df: pl.DataFrame):
# and create a text label for them
df = (
df.filter(pl.col("duration[s]") > limit)
.with_column(
.with_columns(
pl.when(pl.col("success"))
.then(
pl.format(
Expand All @@ -62,7 +62,7 @@ def add_annotations(fig, limit: int, df: pl.DataFrame):
.join(bar_order, on="solution")
.groupby("query_no")
.agg([pl.col("labels").list(), pl.col("index").min()])
.with_column(pl.col("labels").arr.join(",\n"))
.with_columns(pl.col("labels").arr.join(",\n"))
)

# then we create a dictionary similar to something like this:
Expand Down