Skip to content
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
11 changes: 11 additions & 0 deletions python/datafusion/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ def select(self, *exprs: Expr | str) -> DataFrame:
]
return DataFrame(self.df.select(*exprs_internal))

def drop(self, *columns: str) -> DataFrame:
"""Drop arbitrary amount of columns.

Args:
columns: Column names to drop from the dataframe.

Returns:
DataFrame with those columns removed in the projection.
"""
return DataFrame(self.df.drop(*columns))

def filter(self, *predicates: Expr) -> DataFrame:
"""Return a DataFrame for which ``predicate`` evaluates to ``True``.

Expand Down
11 changes: 11 additions & 0 deletions python/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ def test_sort(df):
assert table.to_pydict() == expected


def test_drop(df):
df = df.drop("c")

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

assert df.schema().names == ["a", "b"]
assert result.column(0) == pa.array([1, 2, 3])
assert result.column(1) == pa.array([4, 5, 6])


def test_limit(df):
df = df.limit(1)

Expand Down
7 changes: 7 additions & 0 deletions src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ impl PyDataFrame {
Ok(Self::new(df))
}

#[pyo3(signature = (*args))]
fn drop(&self, args: Vec<PyBackedStr>) -> PyResult<Self> {
let cols = args.iter().map(|s| s.as_ref()).collect::<Vec<&str>>();
let df = self.df.as_ref().clone().drop_columns(&cols)?;
Ok(Self::new(df))
}

fn filter(&self, predicate: PyExpr) -> PyResult<Self> {
let df = self.df.as_ref().clone().filter(predicate.into())?;
Ok(Self::new(df))
Expand Down
Loading