Make polars last consistent with polars first (#15963)

# Description
`polars last` will only return one row by default making it consistent
with `polars first`

# User-Facing Changes
- `polars last` will only return one row by default making it consistent
with `polars first`

Co-authored-by: Jack Wright <jack.wright@nike.com>
This commit is contained in:
Jack Wright 2025-06-13 12:35:26 -07:00 committed by GitHub
parent aa710eeb9a
commit 7972aea530
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,7 @@ use crate::{
values::{Column, CustomValueSupport, NuLazyFrame, NuLazyGroupBy, PolarsPluginObject}, values::{Column, CustomValueSupport, NuLazyFrame, NuLazyGroupBy, PolarsPluginObject},
}; };
use crate::values::{NuDataFrame, NuExpression, utils::DEFAULT_ROWS}; use crate::values::{NuDataFrame, NuExpression};
use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand}; use nu_plugin::{EngineInterface, EvaluatedCall, PluginCommand};
use nu_protocol::{ use nu_protocol::{
Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type, Category, Example, LabeledError, PipelineData, ShellError, Signature, Span, SyntaxShape, Type,
@ -11,6 +11,8 @@ use nu_protocol::{
}; };
use polars::df; use polars::df;
const DEFAULT_ROWS: usize = 1;
#[derive(Clone)] #[derive(Clone)]
pub struct LastDF; pub struct LastDF;
@ -150,7 +152,7 @@ fn command_groupby(
groupby: NuLazyGroupBy, groupby: NuLazyGroupBy,
) -> Result<PipelineData, ShellError> { ) -> Result<PipelineData, ShellError> {
let rows: Option<usize> = call.opt(0)?; let rows: Option<usize> = call.opt(0)?;
let rows = rows.unwrap_or(1); let rows = rows.unwrap_or(DEFAULT_ROWS);
let res = groupby.to_polars().tail(Some(rows)); let res = groupby.to_polars().tail(Some(rows));
let res: NuLazyFrame = res.into(); let res: NuLazyFrame = res.into();