Skip to content

[DataFrame] - Add DataFrame::distinct binding #34

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

Merged
merged 3 commits into from
Sep 8, 2022
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target
Cargo.lock
/venv
.idea

# Byte-compiled / optimized / DLL files
Expand Down
24 changes: 24 additions & 0 deletions datafusion/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,30 @@ def test_join():
assert table.to_pydict() == expected


def test_distinct():
ctx = SessionContext()

batch = pa.RecordBatch.from_arrays(
[pa.array([1, 2, 3, 1, 2, 3]), pa.array([4, 5, 6, 4, 5, 6])],
names=["a", "b"],
)
df_a = (
ctx.create_dataframe([[batch]])
.distinct()
.sort(column("a").sort(ascending=True))
)

batch = pa.RecordBatch.from_arrays(
[pa.array([1, 2, 3]), pa.array([4, 5, 6])],
names=["a", "b"],
)
df_b = ctx.create_dataframe([[batch]]).sort(
column("a").sort(ascending=True)
)

assert df_a.collect() == df_b.collect()


def test_window_lead(df):
df = df.select(
column("a"),
Expand Down
8 changes: 7 additions & 1 deletion src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ impl PyDataFrame {
Ok(pretty::print_batches(&batches)?)
}

/// Filter out duplicate rows
fn distinct(&self) -> PyResult<Self> {
let df = self.df.distinct()?;
Ok(Self::new(df))
}

fn join(
&self,
right: PyDataFrame,
Expand All @@ -147,7 +153,7 @@ impl PyDataFrame {
"The join type {} does not exist or is not implemented",
how
))
.into())
.into());
}
};

Expand Down