Skip to content

Commit

Permalink
COMPAT: ensure argsort output has a stable order in numpy 2 (#725)
Browse files Browse the repository at this point in the history
* TST: sort kernel triangulation output before assertion

* use stable argsort output
  • Loading branch information
martinfleis authored Jun 19, 2024
1 parent a92290b commit 49c2610
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libpysal/graph/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

GPD_013 = Version(geopandas.__version__) >= Version("0.13")
PANDAS_GE_21 = Version(pd.__version__) >= Version("2.1.0")
NUMPY_GE_2 = Version(np.__version__) >= Version("2.0.0")

try:
from numba import njit # noqa: E401
Expand All @@ -31,6 +32,7 @@ def _sparse_to_arrays(sparray, ids=None, resolve_isolates=True, return_adjacency
When we know we are dealing with cliques, we don't want to resolve
isolates here but will do that later once cliques are induced.
"""
argsort_kwds = {"stable": True} if NUMPY_GE_2 else {}
sparray = sparray.tocoo(copy=False)
if ids is not None:
ids = np.asarray(ids)
Expand All @@ -40,12 +42,12 @@ def _sparse_to_arrays(sparray, ids=None, resolve_isolates=True, return_adjacency
f"the shape of sparse {sparray.shape}."
)

sorter = sparray.row.argsort()
sorter = sparray.row.argsort(**argsort_kwds)
head = ids[sparray.row][sorter]
tail = ids[sparray.col][sorter]
data = sparray.data[sorter]
else:
sorter = sparray.row.argsort()
sorter = sparray.row.argsort(**argsort_kwds)
head = sparray.row[sorter]
tail = sparray.col[sorter]
data = sparray.data[sorter]
Expand Down

0 comments on commit 49c2610

Please sign in to comment.