-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Lazy coordinates_to_cells #42
Comments
Whats required for this is being able to call What could be done is implementing an extension of a |
Thanks for looking at this, I was mostly looking at using a |
Hi ^^. In order to take multiple args it could be implemented using the polars plugin system like in https://marcogorelli.github.io/polars-plugins-tutorial/lost_in_space/. Something in the line of #[polars_expr(output_type = UInt64)]
fn coordinates_to_cells(inputs: &[Series], kwargs: H3Kwargs) -> PolarsResult<Series> {
let lats = inputs[0].f64()?;
let lons = inputs[1].f64()?;
let resolution = Resolution::try_from(kwargs.resolution).unwrap();
let mut cells: Vec<u64> = Vec::with_capacity(lats.len());
lats.iter().zip(lons.iter()).for_each(|(lat, lon)| {
if let (Some(lat), Some(lon)) = (lat, lon) {
cells.push(u64::from(LatLng::new(lat, lon).unwrap().to_cell(resolution)))
}
});
Ok(UInt64Chunked::from_vec("cells", cells).into_series())
} and then register the function in pythonland with: import polars as pl
from polars.plugins import register_plugin_function
from polars.type_aliases import IntoExpr
def coordinates_to_cells(lat: IntoExpr, lon: IntoExpr,*, resolution: int) -> pl.Expr:
return register_plugin_function(
plugin_path=Path(__file__).parent,
args=[lat, lon],
kwargs={"resolution": resolution},
function_name="coordinates_to_cells",
is_elementwise=True,
) Would allow us to operate on the LazyFrame example as such
However, this needs a custom plugin in rust land which needs to be build as a polars plugin :/ I guess it can be done using the existing h3ronpy function
But the documentation falls short and I did not find anything similar in the wilderness |
I am a new polars user and I am curious how do I use the
coordinates_to_cells
function in a lazy context?If I do what I think needs to be done I get an error
TypeError: 'Expr' object is not iterable
I can achieve my goal in the eager way. But hoping I can do this with the lazy api?The text was updated successfully, but these errors were encountered: