From 3f86dfb89cb43e56a67be8341663963d5f2a74c4 Mon Sep 17 00:00:00 2001 From: Bifbof Date: Sat, 11 May 2024 13:11:49 +0200 Subject: [PATCH] fix `ravel` deprecation warning for `Series` Fix deprecation warning by making cast to numpy array explicit. --- tests/geogr/test_distances.py | 2 +- trackintel/geogr/distances.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/geogr/test_distances.py b/tests/geogr/test_distances.py index 48262ab2..2947b190 100644 --- a/tests/geogr/test_distances.py +++ b/tests/geogr/test_distances.py @@ -435,7 +435,7 @@ def test_one_speed(self, load_positionfixes): time_diff = (pfs.loc[ind, "tracked_at"] - pfs.loc[ind_prev, "tracked_at"]).total_seconds() point1 = pfs.loc[ind_prev, "geom"] point2 = pfs.loc[ind, "geom"] - dist = point_haversine_dist(point1.x, point1.y, point2.x, point2.y)[0] + dist = point_haversine_dist(point1.x, point1.y, point2.x, point2.y) assert np.isclose(dist / time_diff, computed_speeds[ind], rtol=1e-06) assert np.isclose(dist / time_diff, correct_speeds[ind], rtol=1e-06) diff --git a/trackintel/geogr/distances.py b/trackintel/geogr/distances.py index ce3b04cf..42470368 100644 --- a/trackintel/geogr/distances.py +++ b/trackintel/geogr/distances.py @@ -67,10 +67,16 @@ def point_haversine_dist(lon_1, lat_1, lon_2, lat_2, r=6371000, float_flag=False return r * math.acos(cos_lat_d - cos_lat1 * cos_lat2 * (1 - cos_lon_d)) - lon_1 = np.deg2rad(lon_1).ravel() - lat_1 = np.deg2rad(lat_1).ravel() - lon_2 = np.deg2rad(lon_2).ravel() - lat_2 = np.deg2rad(lat_2).ravel() + if all(isinstance(x, pd.Series) for x in [lon_1, lat_1, lon_2, lat_2]): + lon_1 = lon_1.to_numpy() + lat_1 = lat_1.to_numpy() + lon_2 = lon_2.to_numpy() + lat_2 = lat_2.to_numpy() + + lon_1 = np.deg2rad(lon_1) + lat_1 = np.deg2rad(lat_1) + lon_2 = np.deg2rad(lon_2) + lat_2 = np.deg2rad(lat_2) cos_lat1 = np.cos(lat_1) cos_lat2 = np.cos(lat_2)