FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[DataFrame] - Add DataFrame::distinct binding by francis-du · Pull Request #34 · apache/datafusion-python · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) .rs  (1) dotfile  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions .gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL