-
Notifications
You must be signed in to change notification settings - Fork 61
Inverse postal code search #87
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
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
rth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! a few comments below and this also needs some unit tests.
|
|
||
| Args: | ||
| lat (float): latitude | ||
| lon (float): longitude |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use numpy style docstring.
|
|
||
| return pd.DataFrame(columns=self._data.columns) | ||
|
|
||
| def query_geocode(self, lat: float, lon: float): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's call it query_coordinates maybe.
Also I think it would be better to also add a top_k: int=1 param and returns a dataframe not a series, similar to how query_location works. Add the return type annotations.
| np.array([[lat, lon]]), np.array([[row["latitude"], row["longitude"]]]) | ||
| ), | ||
| axis=1, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can build the array of coordinates _data_frame and pass it to haversine_distance directly (it should work with arrays of shape N, that would be faster.
| nearest_index = distances.idxmin() | ||
|
|
||
| # Return the nearest row | ||
| nearest_row = self._data_frame.loc[nearest_index].copy() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can argsort distances and return top_k
#7
Feel free to edit as you wish