Skip to content

Commit

Permalink
Rename on Rust side
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Jan 6, 2024
1 parent ae20037 commit 077948b
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion crates/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl DataFrame {
/// | 3 | Patricia |
/// +-----+----------+
/// ```
pub fn with_row_count(&self, name: &str, offset: Option<IdxSize>) -> PolarsResult<Self> {
pub fn with_row_number(&self, name: &str, offset: Option<IdxSize>) -> PolarsResult<Self> {
let mut columns = Vec::with_capacity(self.columns.len() + 1);
let offset = offset.unwrap_or(0);

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ impl LazyFrame {
/// # Warning
/// This can have a negative effect on query performance. This may for instance block
/// predicate pushdown optimization.
pub fn with_row_count(mut self, name: &str, offset: Option<IdxSize>) -> LazyFrame {
pub fn with_row_number(mut self, name: &str, offset: Option<IdxSize>) -> LazyFrame {
let add_row_count_in_map = match &mut self.logical_plan {
LogicalPlan::Scan {
file_options: options,
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/scan/anonymous_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl LazyFrame {
.into();

if let Some(rc) = args.row_count {
lf = lf.with_row_count(&rc.name, Some(rc.offset))
lf = lf.with_row_number(&rc.name, Some(rc.offset))
};

Ok(lf)
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/scan/file_list_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub trait LazyFileListReader: Clone {
lf = lf.slice(0, n_rows as IdxSize)
};
if let Some(rc) = self.row_count() {
lf = lf.with_row_count(&rc.name, Some(rc.offset))
lf = lf.with_row_number(&rc.name, Some(rc.offset))
};

Ok(lf)
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/scan/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl LazyFileListReader for LazyIpcReader {

// it is a bit hacky, but this row_count function updates the schema
if let Some(row_count) = args.row_count {
lf = lf.with_row_count(&row_count.name, Some(row_count.offset))
lf = lf.with_row_number(&row_count.name, Some(row_count.offset))
}

Ok(lf)
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-lazy/src/scan/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl LazyFileListReader for LazyParquetReader {

// it is a bit hacky, but this row_count function updates the schema
if let Some(row_count) = row_count {
lf = lf.with_row_count(&row_count.name, Some(row_count.offset))
lf = lf.with_row_number(&row_count.name, Some(row_count.offset))
}

lf.opt_state.file_caching = true;
Expand Down
20 changes: 10 additions & 10 deletions crates/polars-lazy/src/tests/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,42 +373,42 @@ fn test_row_count_on_files() -> PolarsResult<()> {
for offset in [0 as IdxSize, 10] {
let lf = LazyCsvReader::new(FOODS_CSV)
.with_row_count(Some(RowCount {
name: "rc".into(),
name: "rn".into(),
offset,
}))
.finish()?;

assert!(row_count_at_scan(lf.clone()));
let df = lf.collect()?;
let rc = df.column("rc")?;
let rn = df.column("rn")?;
assert_eq!(
rc.idx()?.into_no_null_iter().collect::<Vec<_>>(),
rn.idx()?.into_no_null_iter().collect::<Vec<_>>(),
(offset..27 + offset).collect::<Vec<_>>()
);

let lf = LazyFrame::scan_parquet(FOODS_PARQUET, Default::default())?
.with_row_count("rc", Some(offset));
.with_row_number("rn", Some(offset));
assert!(row_count_at_scan(lf.clone()));
let df = lf.collect()?;
let rc = df.column("rc")?;
let rn = df.column("rn")?;
assert_eq!(
rc.idx()?.into_no_null_iter().collect::<Vec<_>>(),
rn.idx()?.into_no_null_iter().collect::<Vec<_>>(),
(offset..27 + offset).collect::<Vec<_>>()
);

let lf =
LazyFrame::scan_ipc(FOODS_IPC, Default::default())?.with_row_count("rc", Some(offset));
LazyFrame::scan_ipc(FOODS_IPC, Default::default())?.with_row_number("rn", Some(offset));

assert!(row_count_at_scan(lf.clone()));
let df = lf.clone().collect()?;
let rc = df.column("rc")?;
let rn = df.column("rn")?;
assert_eq!(
rc.idx()?.into_no_null_iter().collect::<Vec<_>>(),
rn.idx()?.into_no_null_iter().collect::<Vec<_>>(),
(offset..27 + offset).collect::<Vec<_>>()
);

let out = lf
.filter(col("rc").gt(lit(-1)))
.filter(col("rn").gt(lit(-1)))
.select([col("calories")])
.collect()?;
assert!(out.column("calories").is_ok());
Expand Down
20 changes: 10 additions & 10 deletions crates/polars-lazy/src/tests/optimization_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,23 +351,23 @@ fn test_with_row_count_opts() -> PolarsResult<()> {
let out = df
.clone()
.lazy()
.with_row_count("row_nr", None)
.with_row_number("row_number", None)
.tail(5)
.collect()?;
let expected = df![
"row_nr" => [5 as IdxSize, 6, 7, 8, 9],
"row_number" => [5 as IdxSize, 6, 7, 8, 9],
"a" => [5, 6, 7, 8, 9],
]?;

assert!(out.equals(&expected));
let out = df
.clone()
.lazy()
.with_row_count("row_nr", None)
.with_row_number("row_number", None)
.slice(1, 2)
.collect()?;
assert_eq!(
out.column("row_nr")?
out.column("row_number")?
.idx()?
.into_no_null_iter()
.collect::<Vec<_>>(),
Expand All @@ -377,11 +377,11 @@ fn test_with_row_count_opts() -> PolarsResult<()> {
let out = df
.clone()
.lazy()
.with_row_count("row_nr", None)
.with_row_number("row_number", None)
.filter(col("a").eq(lit(3i32)))
.collect()?;
assert_eq!(
out.column("row_nr")?
out.column("row_number")?
.idx()?
.into_no_null_iter()
.collect::<Vec<_>>(),
Expand All @@ -392,10 +392,10 @@ fn test_with_row_count_opts() -> PolarsResult<()> {
.clone()
.lazy()
.slice(1, 2)
.with_row_count("row_nr", None)
.with_row_number("row_number", None)
.collect()?;
assert_eq!(
out.column("row_nr")?
out.column("row_number")?
.idx()?
.into_no_null_iter()
.collect::<Vec<_>>(),
Expand All @@ -405,10 +405,10 @@ fn test_with_row_count_opts() -> PolarsResult<()> {
let out = df
.lazy()
.filter(col("a").eq(lit(3i32)))
.with_row_count("row_nr", None)
.with_row_number("row_number", None)
.collect()?;
assert_eq!(
out.column("row_nr")?
out.column("row_number")?
.idx()?
.into_no_null_iter()
.collect::<Vec<_>>(),
Expand Down
8 changes: 4 additions & 4 deletions crates/polars-lazy/src/tests/projection_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ fn test_cross_join_pd() -> PolarsResult<()> {
}

#[test]
fn test_row_count_pd() -> PolarsResult<()> {
fn test_row_number_pd() -> PolarsResult<()> {
let df = df![
"x" => [1, 2, 3],
"y" => [3, 2, 1],
]?;

let df = df
.lazy()
.with_row_count("row_count", None)
.select([col("row_count"), col("x") * lit(3i32)])
.with_row_number("row_number", None)
.select([col("row_number"), col("x") * lit(3i32)])
.collect()?;

let expected = df![
"row_count" => [0 as IdxSize, 1, 2],
"row_number" => [0 as IdxSize, 1, 2],
"x" => [3i32, 6, 9]
]?;

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-plan/src/logical_plan/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl FunctionNode {
let args = (**args).clone();
df.melt2(args)
},
RowCount { name, offset, .. } => df.with_row_count(name.as_ref(), *offset),
RowCount { name, offset, .. } => df.with_row_number(name.as_ref(), *offset),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/polars/tests/it/lazy/explodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ fn test_explode_row_numbers() -> PolarsResult<()> {
]?
.lazy()
.select([col("text").str().split(lit(" ")).alias("tokens")])
.with_row_count("row_nr", None)
.with_row_number("row_number", None)
.explode([col("tokens")])
.select([col("row_nr"), col("tokens")])
.select([col("row_number"), col("tokens")])
.collect()?;

assert_eq!(df.shape(), (8, 2));
Expand Down
6 changes: 3 additions & 3 deletions crates/polars/tests/it/lazy/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ fn test_sorted_path() -> PolarsResult<()> {

let out = df
.lazy()
.with_row_count("row_nr", None)
.with_row_number("row_number", None)
.explode(["a"])
.group_by(["row_nr"])
.group_by(["row_number"])
.agg([col("a").count().alias("count")])
.collect()?;

let s = out.column("row_nr")?;
let s = out.column("row_number")?;
assert_eq!(s.is_sorted_flag(), IsSorted::Ascending);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rust/user-guide/expressions/column-selections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"logged_at" => date_range("logged_at",
NaiveDate::from_ymd_opt(2022, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(), NaiveDate::from_ymd_opt(2022, 1, 1).unwrap().and_hms_opt(0, 0, 2).unwrap(), Duration::parse("1s"),ClosedWindow::Both, TimeUnit::Milliseconds, None)?,
)?
.with_row_count("rn", None)?;
.with_row_number("rn", None)?;
println!("{}", &df);
// --8<-- [end:selectors_df]

Expand Down
2 changes: 1 addition & 1 deletion py-polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,7 @@ impl PyDataFrame {
pub fn with_row_number(&self, name: &str, offset: Option<IdxSize>) -> PyResult<Self> {
let df = self
.df
.with_row_count(name, offset)
.with_row_number(name, offset)
.map_err(PyPolarsErr::from)?;
Ok(df.into())
}
Expand Down
2 changes: 1 addition & 1 deletion py-polars/src/lazyframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ impl PyLazyFrame {

fn with_row_number(&self, name: &str, offset: Option<IdxSize>) -> Self {
let ldf = self.ldf.clone();
ldf.with_row_count(name, offset).into()
ldf.with_row_number(name, offset).into()
}

#[pyo3(signature = (lambda, predicate_pushdown, projection_pushdown, slice_pushdown, streamable, schema, validate_output))]
Expand Down

0 comments on commit 077948b

Please sign in to comment.