Skip to content

Commit

Permalink
Consistently use ns for namespace in docs/examples (#328)
Browse files Browse the repository at this point in the history
* consistently use ns for namespace

* use pdx instead of ns

* use pdx instead of ns

* pdx
  • Loading branch information
MarcoGorelli authored Nov 22, 2023
1 parent 27d5fc4 commit 4980320
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 36 deletions.
14 changes: 7 additions & 7 deletions spec/API_specification/dataframe_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ def date(year: int, month: int, day: int) -> Scalar:
Examples
--------
>>> df: DataFrame
>>> namespace = df.__dataframe_namespace__()
>>> pdx = df.__dataframe_namespace__()
>>> mask = (
... (df.get_column_by_name('date') >= namespace.date(2020, 1, 1))
... & (df.get_column_by_name('date') < namespace.date(2021, 1, 1))
... (df.get_column_by_name('date') >= pdx.date(2020, 1, 1))
... & (df.get_column_by_name('date') < pdx.date(2021, 1, 1))
... )
>>> df.filter(mask)
"""
Expand All @@ -319,8 +319,8 @@ def any_horizontal(*columns: Column, skip_nulls: bool = True) -> Column:
Examples
--------
>>> df: DataFrame
>>> ns = df.__dataframe_namespace__()
>>> mask = ns.any_horizontal(
>>> pdx = df.__dataframe_namespace__()
>>> mask = pdx.any_horizontal(
... *[df.col(col_name) > 0 for col_name in df.column_names()]
... )
>>> df = df.filter(mask)
Expand All @@ -345,8 +345,8 @@ def all_horizontal(*columns: Column, skip_nulls: bool = True) -> Column:
Examples
--------
>>> df: DataFrame
>>> ns = df.__dataframe_namespace__()
>>> mask = ns.all_horizontal(
>>> pdx = df.__dataframe_namespace__()
>>> mask = pdx.all_horizontal(
... *[df.col(col_name) > 0 for col_name in df.column_names()]
... )
>>> df = df.filter(mask)
Expand Down
12 changes: 6 additions & 6 deletions spec/API_specification/dataframe_api/groupby_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ def aggregate(self, *aggregation: Aggregation) -> DataFrame:
Examples
--------
>>> df: DataFrame
>>> namespace = df.__dataframe_namespace__()
>>> pdx = df.__dataframe_namespace__()
>>> df.group_by('year').aggregate(
... namespace.Aggregation.sum('l_quantity').rename('sum_qty'),
... namespace.Aggregation.mean('l_quantity').rename('avg_qty'),
... namespace.Aggregation.mean('l_extended_price').rename('avg_price'),
... namespace.Aggregation.mean('l_discount').rename('avg_disc'),
... namespace.Aggregation.size().rename('count_order'),
... pdx.Aggregation.sum('l_quantity').rename('sum_qty'),
... pdx.Aggregation.mean('l_quantity').rename('avg_qty'),
... pdx.Aggregation.mean('l_extended_price').rename('avg_price'),
... pdx.Aggregation.mean('l_discount').rename('avg_disc'),
... pdx.Aggregation.size().rename('count_order'),
... )
"""
...
Expand Down
4 changes: 2 additions & 2 deletions spec/API_specification/examples/02_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def group_by_and_plot(
y = y_any.__column_consortium_standard__(api_version="2023-10.beta")
color = color_any.__column_consortium_standard__(api_version="2023-10.beta")

namespace = x.__column_namespace__()
pdx = x.__column_namespace__()

df = namespace.dataframe_from_columns(
df = pdx.dataframe_from_columns(
x.rename("x"),
y.rename("y"),
color.rename("color"),
Expand Down
4 changes: 2 additions & 2 deletions spec/API_specification/examples/03_working_with_nulls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

def main(df_raw: SupportsDataFrameAPI) -> SupportsDataFrameAPI:
df = df_raw.__dataframe_consortium_standard__(api_version="2023-11.beta")
namespace = df.__dataframe_namespace__()
df = df.fill_nan(namespace.null)
pdx = df.__dataframe_namespace__()
df = df.fill_nan(pdx.null)
return df.dataframe
8 changes: 4 additions & 4 deletions spec/API_specification/examples/04_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

def main(df_raw: SupportsDataFrameAPI) -> SupportsDataFrameAPI:
df = df_raw.__dataframe_consortium_standard__(api_version="2023-11.beta").persist()
namespace = df.__dataframe_namespace__()
pdx = df.__dataframe_namespace__()
df = df.select(
*[
col_name
for col_name in df.column_names
if isinstance(df.col(col_name).dtype, namespace.Int64)
if isinstance(df.col(col_name).dtype, pdx.Int64)
],
)
arr = df.to_array(namespace.Int64())
arr = df.to_array(pdx.Int64())
arr = some_array_function(arr)
df = namespace.dataframe_from_2d_array(arr, names=["a", "b"])
df = pdx.dataframe_from_2d_array(arr, names=["a", "b"])
return df.dataframe
4 changes: 2 additions & 2 deletions spec/API_specification/examples/06_horizontal_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

def main(df_raw: SupportsDataFrameAPI) -> SupportsDataFrameAPI:
df = df_raw.__dataframe_consortium_standard__(api_version="2023-11.beta")
ns = df.__dataframe_namespace__()
pdx = df.__dataframe_namespace__()
df = df.filter(
ns.any_horizontal(*[df.col(col_name) > 0 for col_name in df.column_names]),
pdx.any_horizontal(*[df.col(col_name) > 0 for col_name in df.column_names]),
)
return df.dataframe
18 changes: 9 additions & 9 deletions spec/API_specification/examples/tpch/q1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

def query(lineitem_raw: SupportsDataFrameAPI) -> Any:
lineitem = lineitem_raw.__dataframe_consortium_standard__(api_version="2023.10-beta")
namespace = lineitem.__dataframe_namespace__()
pdx = lineitem.__dataframe_namespace__()

mask = lineitem.col("l_shipdate") <= namespace.date(1998, 9, 2)
mask = lineitem.col("l_shipdate") <= pdx.date(1998, 9, 2)
lineitem = lineitem.assign(
(lineitem.col("l_extended_price") * (1 - lineitem.col("l_discount"))).rename(
"l_disc_price",
Expand All @@ -25,13 +25,13 @@ def query(lineitem_raw: SupportsDataFrameAPI) -> Any:
lineitem.filter(mask)
.group_by("l_returnflag", "l_linestatus")
.aggregate(
namespace.Aggregation.sum("l_quantity").rename("sum_qty"),
namespace.Aggregation.sum("l_extendedprice").rename("sum_base_price"),
namespace.Aggregation.sum("l_disc_price").rename("sum_disc_price"),
namespace.Aggregation.sum("change").rename("sum_charge"),
namespace.Aggregation.mean("l_quantity").rename("avg_qty"),
namespace.Aggregation.mean("l_discount").rename("avg_disc"),
namespace.Aggregation.size().rename("count_order"),
pdx.Aggregation.sum("l_quantity").rename("sum_qty"),
pdx.Aggregation.sum("l_extendedprice").rename("sum_base_price"),
pdx.Aggregation.sum("l_disc_price").rename("sum_disc_price"),
pdx.Aggregation.sum("change").rename("sum_charge"),
pdx.Aggregation.mean("l_quantity").rename("avg_qty"),
pdx.Aggregation.mean("l_discount").rename("avg_disc"),
pdx.Aggregation.size().rename("count_order"),
)
.sort("l_returnflag", "l_linestatus")
)
Expand Down
8 changes: 4 additions & 4 deletions spec/API_specification/examples/tpch/q5.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def query(
nation = nation_raw.__dataframe_consortium_standard__(api_version="2023-10.beta")
region = region_raw.__dataframe_consortium_standard__(api_version="2023-10.beta")

namespace = customer.__dataframe_namespace__()
pdx = customer.__dataframe_namespace__()

result = (
region.join(nation, how="inner", left_on="r_regionkey", right_on="n_regionkey")
Expand All @@ -56,15 +56,15 @@ def query(
mask = (
(result.col("c_nationkey") == result.col("s_nationkey"))
& (result.col("r_name") == "ASIA")
& (result.col("o_orderdate") >= namespace.date(1994, 1, 1))
& (result.col("o_orderdate") < namespace.date(1995, 1, 1))
& (result.col("o_orderdate") >= pdx.date(1994, 1, 1))
& (result.col("o_orderdate") < pdx.date(1995, 1, 1))
)
result = result.filter(mask)

new_column = (result.col("l_extendedprice") * (1 - result.col("l_discount"))).rename(
"revenue",
)
result = result.assign(new_column)
result = result.group_by("n_name").aggregate(namespace.Aggregation.sum("revenue"))
result = result.group_by("n_name").aggregate(pdx.Aggregation.sum("revenue"))

return result.dataframe

0 comments on commit 4980320

Please sign in to comment.