mie-lab / trackintel

trackintel is a framework for spatio-temporal analysis of movement trajectory and mobility data.
MIT License
198 stars 50 forks source link

BUG: `calculate_distance_matrix` does not compute all distance pairs. #592

Closed bifbof closed 8 months ago

bifbof commented 8 months ago

In calculate_distance_matrix we can either compare an X to itself or to another Y. The code does some optimization for X in assuming that the computation is symmetric and only doing half of the pairs (e.g. (x[0], x[1]) has the same result as (x[1], x[0])). But the same thing is done if a Y is provided, here (x[0], y[1]) can be different to (x[1], y[0]). This code triggers the bug:

import geopandas as gpd
import trackintel as ti
from shapely.geometry import Point
a = [(0, Point(0, 0)), (1, Point(1, 1))]
b = [(0, Point(10, 10)), (1, Point(20, 20))]
a = gpd.GeoDataFrame(a, columns=["id", "g"], geometry="g")
b = gpd.GeoDataFrame(b, columns=["id", "g"], geometry="g")
res = ti.geogr.calculate_distance_matrix(a, b)
assert res[0,0] != 0

Further the whole implementation is full of bugs and smaller issues, things I found at a quick glance:

Further the test suite for this function is not useful. All except one test only compare the output of the function to different output of the function or to nothing at all. The one exception does not provide a Y.