Skip to content

Commit

Permalink
added base to geohashers
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasMAhern committed Jun 19, 2024
1 parent 2f5da97 commit 0565982
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions polars_hash/src/geohashers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ pub fn geohash_encoder(
lat: Option<f64>,
long: Option<f64>,
len: Option<i64>,
base: Option<i64>,
) -> PolarsResult<Option<String>> {
match (lat, long) {
(Some(lat), Some(long)) => match len {
Some(len) => Ok(Some(
encode(Coord { x: long, y: lat }, len as usize)
.map_err(|e| PolarsError::ComputeError(e.to_string().into()))?,
)),
Some(len) => match base {
Some(base) => Ok(Some(
encode(Coord { x: long, y: lat }, len as usize, base as u32)
.map_err(|e| PolarsError::ComputeError(e.to_string().into()))?,
)),
_ => Err(PolarsError::ComputeError(
"Base may not be null".to_string().into(),
)),
},
_ => Err(PolarsError::ComputeError(
"Length may not be null".to_string().into(),
)),
Expand Down

0 comments on commit 0565982

Please sign in to comment.