Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
>>> first_order.mean_neighbors
5.848032564450475
>>> fourth_order = sw_high(k=4, gdf=geodataframe)
>>> fourth.mean_neighbors
85.73188602442333
"""
if weights is not None:
first_order = weights
elif gdf is not None:
if contiguity == "queen":
first_order = libpysal.weights.Queen.from_dataframe(
gdf, ids=ids, silence_warnings=silent
)
elif contiguity == "rook":
first_order = libpysal.weights.Rook.from_dataframe(
gdf, ids=ids, silence_warnings=silent
)
else:
raise ValueError(f"{contiguity} is not supported. Use 'queen' or 'rook'.")
else:
raise AttributeError("GeoDataFrame or spatial weights must be given.")
if k > 1:
id_order = first_order.id_order
w = first_order.sparse
wk = sum(map(lambda x: w ** x, range(2, k + 1)))
rk, ck = wk.nonzero()
sk = set(zip(rk, ck))
sk = set([(i, j) for i, j in sk if i != j])
d = dict([(i, []) for i in id_order])
for pair in sk: