pysal / libpysal

Core components of Python Spatial Analysis Library
http://pysal.org/libpysal
Other
259 stars 78 forks source link

COMPAT: ensure argsort output has a stable order in numpy 2 #725

Closed martinfleis closed 3 months ago

martinfleis commented 3 months ago

Fixes #724

In the end, the results were just in a slightly different order but (head, tail, weight) tuple was always correct. Given we do sorting ourselves in the constructor anyway, this has no impact on creation of graph. Just an intermediate arrays are in different order. Canonically sorting the output before assertion solves the issue.

If you build the full Graph using build_triangulation, they are identical.

martinfleis commented 3 months ago

The explanation is the new stable keyword in argsort - https://numpy.org/doc/stable/reference/generated/numpy.argsort.html

Sort stability. If True, the returned array will maintain the relative order of a values which compare as equal. If False or None, this is not guaranteed. Internally, this option selects kind='stable'. Default: None.

I will actually probably push another commit passing stable=True as I am a bit itchy when it comes to order and graph.

jGaboardi commented 3 months ago

I am +1 for explicit.