bug fixing
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 58s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 58s
This commit is contained in:
@@ -278,8 +278,17 @@ async def get_schools(
|
||||
# Filter by distance using pre-geocoded lat/long from database
|
||||
# Use vectorized haversine calculation for better performance
|
||||
lat1, lon1 = search_coords
|
||||
lat2 = schools_df["latitude"].values
|
||||
lon2 = schools_df["longitude"].values
|
||||
|
||||
# Handle potential duplicate columns by taking first occurrence
|
||||
lat_col = schools_df.loc[:, "latitude"]
|
||||
lon_col = schools_df.loc[:, "longitude"]
|
||||
if isinstance(lat_col, pd.DataFrame):
|
||||
lat_col = lat_col.iloc[:, 0]
|
||||
if isinstance(lon_col, pd.DataFrame):
|
||||
lon_col = lon_col.iloc[:, 0]
|
||||
|
||||
lat2 = lat_col.values
|
||||
lon2 = lon_col.values
|
||||
|
||||
# Vectorized haversine formula
|
||||
R = 3959 # Earth's radius in miles
|
||||
@@ -293,11 +302,8 @@ async def get_schools(
|
||||
distances = R * c
|
||||
|
||||
# Handle missing coordinates
|
||||
distances = np.where(
|
||||
pd.isna(schools_df["latitude"]) | pd.isna(schools_df["longitude"]),
|
||||
float("inf"),
|
||||
distances
|
||||
)
|
||||
has_coords = ~(pd.isna(lat_col) | pd.isna(lon_col))
|
||||
distances = np.where(has_coords.values, distances, float("inf"))
|
||||
schools_df["distance"] = distances
|
||||
schools_df = schools_df[schools_df["distance"] <= radius]
|
||||
schools_df = schools_df.sort_values("distance")
|
||||
|
||||
Reference in New Issue
Block a user