We often return a handle to a roaring bitmap as a Python set, and use a Python set to create a roaring bitmap. Examples:
|
let fragment_ids_ref: &Bound<'_, PySet> = fragment_ids.cast()?; |
|
let fragment_bitmap = Some( |
|
fragment_ids_ref |
|
.into_iter() |
|
.map(|id| id.extract::<u32>()) |
|
.collect::<PyResult<RoaringBitmap>>()?, |
|
); |
|
let fragment_ids = self.0.fragment_bitmap.as_ref().map_or_else( |
|
|| PySet::empty(py).unwrap(), |
|
|bitmap| { |
|
let set = PySet::empty(py).unwrap(); |
|
for id in bitmap.iter() { |
|
set.add(id).unwrap(); |
|
} |
|
set |
|
}, |
|
); |
It might be nice to instead provide a Python type that is a wrapper around Arc<RoaringBitmap>. The bitmap can be passed directly from the Python layer without copies. For mutation, we can do copy on write, use Arc::make_mut().
Bonus points if it has efficient constructors from pyarrow arrays and ranges.
import pyarrow as pa
from lance.bitmap import bitmap
bitmap([1, 2, 4])
bitmap(range(1000))
bitmap(2 * pa.array(range(100)))
We often return a handle to a roaring bitmap as a Python set, and use a Python set to create a roaring bitmap. Examples:
lance/python/src/transaction.rs
Lines 73 to 79 in 41e6e74
lance/python/src/transaction.rs
Lines 126 to 135 in 41e6e74
It might be nice to instead provide a Python type that is a wrapper around
Arc<RoaringBitmap>. The bitmap can be passed directly from the Python layer without copies. For mutation, we can do copy on write, use Arc::make_mut().Bonus points if it has efficient constructors from pyarrow arrays and ranges.