I have a DataFrame containing objects and their coordinates:

```
      id        lat         lng
0   3816  18.384001  -66.114799
1   5922  20.766100 -156.434998
2   1527  21.291394 -157.843085
3   1419  21.291394 -157.843085
4   1651  21.291394 -157.843085

```

Multiple objects can have same coordinates. The dataframe is big (millions of records). I have a target point with coordinates `(target_lat, target_lng)`. My goal is to find objects in the dataframe which are within X miles of the target point, as efficiently as possible.

I'm using `haversine_np` function adapted from [this question](https://stackoverflow.com/a/29546836/304209). It takes parameters `(lat_series, lng_series, lat, lng)` and efficiently computes all distances between `lat_series, lng_series` (two Series) and `(lat, lng)` (two numbers).

Now my question is how to use it to filter the distances and select objects in the original dataframe.

This is my current solution:

```
grouper = df.groupby(['lat', 'lng'], sort=False).grouper
lat_series = grouper.result_index.get_level_values(0)  # lats of unique (lat, lng) pairs
lng_series = grouper.result_index.get_level_values(1)  # lngs of unique (lat, lng) pairs
df['location_index'] = grouper.group_info[0]  # assign index of group back to df
distances = haversine_np(lat_series, lng_series, target_lat, target_lng)
mask = distances <= 50  # let's say 50 miles; boolean mask of size = ngroups
loc_indexes = pd.Series(range(grouper.ngroups))[mask]  # select group indexes by mask
df[df.location_index.isin(loc_indexes)]  # select original records by group indexes

```

It seems to work, although doesn't look reliable, because when I select the relevant group indexes by using `pd.Series(range(grouper.ngroups))[mask]`, I assume that the level values of the grouped are naturally indexed (from 0 to ngroups-1). In other words, I'm relying on the fact that the `i-th` element in `grouper.result_index.get_level_values()` corresponds to the group with label `i` in `grouper.group_info[0]`. I couldn't find a more explicit way to get that mapping.

Questions:

1. Is the method I'm using reliable?
2. Is there a better (safer / more concise / more efficient) method?