Skip to content
This repository has been archived by the owner on Jul 25, 2022. It is now read-only.

Commit

Permalink
Implement select_columns (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove authored Mar 15, 2022
1 parent dc26c19 commit cc1649a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions datafusion/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ def test_select(df):
assert result.column(1) == pa.array([-3, -3, -3])


def test_select_colums(df):
df = df.select_columns("b", "a")

# execute and collect the first (and only) batch
result = df.collect()[0]

assert result.column(0) == pa.array([4, 5, 6])
assert result.column(1) == pa.array([1, 2, 3])


def test_filter(df):
df = df.select(
column("a") + column("b"),
Expand Down
6 changes: 6 additions & 0 deletions src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ impl PyDataFrame {
self.df.schema().into()
}

#[args(args = "*")]
fn select_columns(&self, args: Vec<&str>) -> PyResult<Self> {
let df = self.df.select_columns(&args)?;
Ok(Self::new(df))
}

#[args(args = "*")]
fn select(&self, args: Vec<PyExpr>) -> PyResult<Self> {
let expr = args.into_iter().map(|e| e.into()).collect();
Expand Down

0 comments on commit cc1649a

Please sign in to comment.