Skip to content

Commit

Permalink
Implement describe method (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
simicd authored Mar 21, 2023
1 parent e50e204 commit 024ba3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
24 changes: 24 additions & 0 deletions datafusion/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,3 +607,27 @@ def test_to_pydict(df):
pydict = df.to_pydict()
assert type(pydict) == dict
assert pydict == {"a": [1, 2, 3], "b": [4, 5, 6], "c": [8, 5, 8]}


def test_describe(df):

# Calculate statistics
df = df.describe()

# Collect the result
result = df.to_pydict()

assert result == {
"describe": [
"count",
"null_count",
"mean",
"std",
"min",
"max",
"median",
],
"a": [3.0, 3.0, 2.0, 1.0, 1.0, 3.0, 2.0],
"b": [3.0, 3.0, 5.0, 1.0, 4.0, 6.0, 5.0],
"c": [3.0, 3.0, 7.0, 1.7320508075688772, 5.0, 8.0, 8.0],
}
7 changes: 7 additions & 0 deletions src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ impl PyDataFrame {
}
}

/// Calculate summary statistics for a DataFrame
fn describe(&self, py: Python) -> PyResult<Self> {
let df = self.df.as_ref().clone();
let stat_df = wait_for_future(py, df.describe())?;
Ok(Self::new(stat_df))
}

/// Returns the schema from the logical plan
fn schema(&self) -> PyArrowType<Schema> {
PyArrowType(self.df.schema().into())
Expand Down

0 comments on commit 024ba3a

Please sign in to comment.