def test_attriberror_on_missing_geometries(self):
     test_gdf_1 = test_gdf_no_geom
     test_gdf_2 = test_gdf_no_geom
     expected_message = "At least one of the arguments provided do not have geometry information."
     with pytest.raises(AttributeError) as exception_info:
         functions.nearest_neighbor_analysis(test_gdf_1, test_gdf_2)
     error_message = "Expected the following message: {}. Got the following: {}".format(expected_message, exception_info)
     assert exception_info.match(expected_message), error_message
 def test_attriberror_on_uneven_crs(self):
     test_geodataframe_1 = test_gdf
     test_geodataframe_2 = test_gdf_diff_crs
     expected_message = ("The arguments provided to do not share the same crs."
                     "Got {} and {} as crs.").format(test_geodataframe_1.crs, test_geodataframe_2.crs)
     with pytest.raises(AttributeError) as exception_info:
         functions.nearest_neighbor_analysis(test_geodataframe_1, test_geodataframe_2)
     error_message = "Expected the following message: {}. Got the following: {}".format(expected_message, exception_info)
     assert exception_info.match(expected_message), error_message
 def test_valerror_on_mixed_arguments_gdf_and_df(self):
     test_gdf_1 = test_gdf
     test_gdf_2 = test_df
     expected_message = ("Both arguments should be geopandas.GeoDataFrame objects."
                   "Got {} and {} as object types.").format(type(test_gdf_1), type(test_gdf_2))
     with pytest.raises(ValueError) as exception_info:
         functions.nearest_neighbor_analysis(test_gdf_1, test_gdf_2)
     error_message = "Expected the following message: {}. Got the following: {}".format(expected_message, exception_info)
     assert exception_info.match(expected_message), error_message
dname = os.path.dirname(abspath)
os.chdir(dname)

#%% --- Import Data ---

#Import airbnb data
import_fp = Path(
    "../../data/processed/istanbul_airbnb_processed_shapefile.shp")
airbnb_gdf = gpd.read_file(import_fp, encoding="utf-8-sig")

#Import htourism centers data
import_fp = Path("../../data/processed/htourism_centers_processed.shp")
htourism_gdf = gpd.read_file(import_fp, encoding="utf-8-sig")
#%% --- Conduct Nearest Neighbor Analysis for all districts - without normalization ---

nn_analysis_results_all = nearest_neighbor_analysis(airbnb_gdf, htourism_gdf)

#%% --- Conduct Nearest Neighbor Analysis for all districts - with normalization ---

#Calculate iqr, q1 and q3 for price
price_iqr = iqr(airbnb_gdf.loc[:, "price"], axis=0)
q1 = airbnb_gdf.loc[:, "price"].quantile(0.25)
q3 = airbnb_gdf.loc[:, "price"].quantile(0.75)

#Create masks to select values within IQR
min_mask = airbnb_gdf.loc[:, "price"] >= q1 - (price_iqr * 1.5)
max_mask = airbnb_gdf.loc[:, "price"] <= q3 + (price_iqr * 1.5)
combined_mask = min_mask & max_mask

#Select values according to mask
airbnb_gdf_normalized = airbnb_gdf[combined_mask]