Skip to content
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

feat: expose offset in python API #437

Merged
merged 1 commit into from
Jul 24, 2023
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 datafusion/tests/test_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,17 @@ def test_limit(df):
assert len(result.column(1)) == 1


def test_limit_with_offset(df):
# only 3 rows, but limit past the end to ensure that offset is working
df = df.limit(5, offset=2)

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

assert len(result.column(0)) == 1
assert len(result.column(1)) == 1


def test_with_column(df):
df = df.with_column("c", column("a") + column("b"))

Expand Down
8 changes: 8 additions & 0 deletions datafusion/tests/test_expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ def test_limit(test_ctx):

plan = plan.to_variant()
assert isinstance(plan, Limit)
assert plan.skip() == 0

df = test_ctx.sql("select c1 from test LIMIT 10 OFFSET 5")
plan = df.logical_plan()

plan = plan.to_variant()
assert isinstance(plan, Limit)
assert plan.skip() == 5


def test_aggregate_query(test_ctx):
Expand Down
5 changes: 3 additions & 2 deletions src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,9 @@ impl PyDataFrame {
Ok(Self::new(df))
}

fn limit(&self, count: usize) -> PyResult<Self> {
let df = self.df.as_ref().clone().limit(0, Some(count))?;
#[pyo3(signature = (count, offset=0))]
fn limit(&self, count: usize, offset: usize) -> PyResult<Self> {
let df = self.df.as_ref().clone().limit(offset, Some(count))?;
Ok(Self::new(df))
}

Expand Down
Loading