fix(python): accept optional discard_weight in split_hash (#5116)

### Problem

`PermutationBuilder.split_hash()` raises `TypeError` when
`discard_weight` is omitted because the Python wrapper forwards `None`
while the PyO3 binding requires `u64`. The `_lancedb.pyi` stub also
disagrees with the native signature: it omits `split_names` and types
`discard_weight` as non-optional.

### Behavior

The native binding accepts an optional `discard_weight` and treats
omitted/`None` as `0`, so `split_hash(..., split_names=[...])` works
without passing a discard weight. The stub now matches the binding. A
regression test verifies that omitting `discard_weight` assigns every
row exactly like explicit `0`.

Fixes OSS-2856.
This commit is contained in:
Xuanwo
2026-11-20 20:20:34 +08:00
committed by GitHub
parent 4ac2728e73
commit a9be4525a0
3 changed files with 44 additions and 3 deletions
+3 -2
View File
@@ -123,14 +123,15 @@ impl PyAsyncPermutationBuilder {
})
}
#[pyo3(signature = (columns, split_weights, *, discard_weight=0, split_names=None))]
#[pyo3(signature = (columns, split_weights, *, discard_weight=None, split_names=None))]
pub fn split_hash(
slf: PyRefMut<'_, Self>,
columns: Vec<String>,
split_weights: Vec<u64>,
discard_weight: u64,
discard_weight: Option<u64>,
split_names: Option<Vec<String>>,
) -> PyResult<Self> {
let discard_weight = discard_weight.unwrap_or(0);
slf.modify(|builder| {
builder.with_split_strategy(
SplitStrategy::Hash {