Skip to content

Commit

Permalink
fix(rust, python): panic when max_len -1 is reached (#6494)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Jan 27, 2023
1 parent 861c26f commit 95de367
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions polars/polars-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ parquet = ["arrow/io_parquet"]

# scale to terabytes?
bigidx = ["polars-arrow/bigidx"]
python = []

serde-lazy = ["serde", "polars-arrow/serde", "indexmap/serde"]

Expand Down
12 changes: 11 additions & 1 deletion polars/polars-core/src/chunked_array/ops/chunkops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,17 @@ impl<T: PolarsDataType> ChunkedArray<T> {
_ => chunks.iter().fold(0, |acc, arr| acc + arr.len()),
}
}
self.length = inner(&self.chunks) as IdxSize
self.length = inner(&self.chunks) as IdxSize;
#[cfg(feature = "python")]
assert!(
self.length < IdxSize::MAX,
"Polars' maximum length reached. Consider installing 'polars-u64-idx'."
);
#[cfg(not(feature = "python"))]
assert!(
self.length < IdxSize::MAX,
"Polars' maximum length reached. Consider compiling with 'bigidx' feature."
);
}

pub fn rechunk(&self) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion py-polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ libc = "0.2"
ndarray = "0.15"
numpy = "0.16"
once_cell = "1"
polars-core = { path = "../polars/polars-core", default-features = false }
polars-core = { path = "../polars/polars-core", features = ["python"], default-features = false }
polars-lazy = { path = "../polars/polars-lazy", features = ["python"], default-features = false }
pyo3 = { version = "0.16", features = ["abi3-py37", "extension-module", "multiple-pymethods"] }
pyo3-built = { version = "0.4", optional = true }
Expand Down

0 comments on commit 95de367

Please sign in to comment.