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
12 changes: 10 additions & 2 deletions crates/core/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ use datafusion::dataframe::{DataFrame, DataFrameWriteOptions};
use datafusion::error::DataFusionError;
use datafusion::execution::SendableRecordBatchStream;
use datafusion::execution::context::TaskContext;
use datafusion::logical_expr::SortExpr;
use datafusion::logical_expr::dml::InsertOp;
use datafusion::logical_expr::{LogicalPlan, SortExpr};
use datafusion::parquet::basic::{BrotliLevel, Compression, GzipLevel, ZstdLevel};
use datafusion::physical_plan::{
ExecutionPlan as DFExecutionPlan, collect as df_collect,
Expand Down Expand Up @@ -707,7 +707,15 @@ impl PyDataFrame {
/// Print the result, 20 lines by default
#[pyo3(signature = (num=20))]
fn show(&self, py: Python, num: usize) -> PyDataFusionResult<()> {
let df = self.df.as_ref().clone().limit(0, Some(num))?;
let mut df = self.df.as_ref().clone();
df = match self.df.logical_plan() {
LogicalPlan::Explain(_) | LogicalPlan::Analyze(_) => {
// Explain and Analyzer require they are at the top
// of the plan, so do not add a limit.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

df
}
_ => df.limit(0, Some(num))?,
};
print_dataframe(py, df)
}

Expand Down
10 changes: 10 additions & 0 deletions python/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,16 @@ def test_show_empty(df, capsys):
assert "DataFrame has no rows" in captured.out


def test_show_on_explain(ctx, capsys):
ctx.sql("explain select 1").show()
captured = capsys.readouterr()
assert "1 as Int64(1)" in captured.out

ctx.sql("explain analyze select 1").show()
captured = capsys.readouterr()
assert "1 as Int64(1)" in captured.out


def test_sort(df):
df = df.sort(column("b").sort(ascending=False))

Expand Down
Loading