A kdtree is being used in a get_store_count function. The function is supposed to get us the number of stores around a point, within a given radius (.3 miles in this case)
The nearby_store_count column should have different values. The function is instead setting the values of that column to be the length of the cig_data dataset.
Hi Jendri, thank you for this question. I forgot to mention this, but PySAL 2 also changed the return values of KDTree.query
.
OLD
relative_indices = indices[~np.isnan(indices)]
NEW
relative_indices = indices[indices < store_count]
Here is the updated function that is specific to your code.
radius_in_miles = 0.3
store_count = len(cig_data)
def get_store_count(r):
xy = r['Longitude'], r['Latitude']
distances, indices = store_tree.query(
xy, k=store_count, distance_upper_bound=radius_in_miles)
return sum(indices < store_count)
data['nearby_store_count'] = data.apply(
get_store_count, axis=1)