From dc838800be58889c5d157daeaa99b4aa65cdb8ff Mon Sep 17 00:00:00 2001 From: eli knaap Date: Wed, 28 Feb 2024 12:45:01 -0800 Subject: [PATCH 1/5] xdist mark to isochrone tests --- geosnap/tests/test_isochrones.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/geosnap/tests/test_isochrones.py b/geosnap/tests/test_isochrones.py index a05d91a5..7d3a8435 100644 --- a/geosnap/tests/test_isochrones.py +++ b/geosnap/tests/test_isochrones.py @@ -8,6 +8,7 @@ import pandana as pdna import geopandas as gpd import os +import pytest if not os.path.exists("./41740.h5"): import quilt3 as q3 @@ -20,12 +21,12 @@ sd_network = pdna.Network.from_hdf5("41740.h5") example_origin = 1985327805 - +@pytest.mark.xdist_group(name="group1") def test_isos_from_ids(): iso = isochrones_from_id(example_origin, sd_network, threshold=1600) assert iso.area.round(6).tolist()[0] == 0.000128 - +@pytest.mark.xdist_group(name="group1") def test_isos_from_gdf(): sd_network.nodes_df["geometry"] = gpd.points_from_xy( sd_network.nodes_df.x, sd_network.nodes_df.y From 16dd1190383609d9981a83c33bdb3c5ea65b7fd1 Mon Sep 17 00:00:00 2001 From: eli knaap Date: Wed, 28 Feb 2024 12:52:01 -0800 Subject: [PATCH 2/5] move data inside function --- geosnap/tests/test_isochrones.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/geosnap/tests/test_isochrones.py b/geosnap/tests/test_isochrones.py index 7d3a8435..bd8fd393 100644 --- a/geosnap/tests/test_isochrones.py +++ b/geosnap/tests/test_isochrones.py @@ -10,24 +10,27 @@ import os import pytest -if not os.path.exists("./41740.h5"): - import quilt3 as q3 +def get_data(): + if not os.path.exists("./41740.h5"): + import quilt3 as q3 - b = q3.Bucket("s3://spatial-ucr") - b.fetch("osm/metro_networks_8k/41740.h5", "./41740.h5") + b = q3.Bucket("s3://spatial-ucr") + b.fetch("osm/metro_networks_8k/41740.h5", "./41740.h5") + sd_network = pdna.Network.from_hdf5("41740.h5") + example_origin = 1985327805 + + return example_origin, sd_network -datasets = DataStore() -sd_tracts = get_acs(datasets, county_fips="06073", years=[2018]) -sd_network = pdna.Network.from_hdf5("41740.h5") -example_origin = 1985327805 @pytest.mark.xdist_group(name="group1") def test_isos_from_ids(): + example_origin, sd_network = get_data() iso = isochrones_from_id(example_origin, sd_network, threshold=1600) assert iso.area.round(6).tolist()[0] == 0.000128 @pytest.mark.xdist_group(name="group1") def test_isos_from_gdf(): + example_origin, sd_network = get_data() sd_network.nodes_df["geometry"] = gpd.points_from_xy( sd_network.nodes_df.x, sd_network.nodes_df.y ) From 2f9c6a9b0c540a100f636899924a5cf3efcf7ddf Mon Sep 17 00:00:00 2001 From: eli knaap Date: Wed, 28 Feb 2024 15:07:54 -0800 Subject: [PATCH 3/5] try casting to float for windows --- geosnap/tests/test_isochrones.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/geosnap/tests/test_isochrones.py b/geosnap/tests/test_isochrones.py index bd8fd393..917d051b 100644 --- a/geosnap/tests/test_isochrones.py +++ b/geosnap/tests/test_isochrones.py @@ -2,13 +2,13 @@ isochrones_from_id, isochrones_from_gdf, ) -from geosnap.io import get_acs -from geosnap import DataStore import pandana as pdna import geopandas as gpd import os import pytest +from numpy.testing import assert_almost_equal + def get_data(): if not os.path.exists("./41740.h5"): @@ -18,7 +18,7 @@ def get_data(): b.fetch("osm/metro_networks_8k/41740.h5", "./41740.h5") sd_network = pdna.Network.from_hdf5("41740.h5") example_origin = 1985327805 - + return example_origin, sd_network @@ -26,7 +26,8 @@ def get_data(): def test_isos_from_ids(): example_origin, sd_network = get_data() iso = isochrones_from_id(example_origin, sd_network, threshold=1600) - assert iso.area.round(6).tolist()[0] == 0.000128 + assert_almost_equal(iso.area.round(6).astype(float).tolist()[0], 0.000128) + @pytest.mark.xdist_group(name="group1") def test_isos_from_gdf(): @@ -43,4 +44,4 @@ def test_isos_from_gdf(): network=sd_network, threshold=1600, ) - assert t.area.round(8).tolist()[0] == 0.00012821 + assert_almost_equal(t.area.astype(float).round(8).tolist()[0], 0.00012821) From 147d924aff75b63418e1c4c8ce8f21aa4db65ca1 Mon Sep 17 00:00:00 2001 From: eli knaap Date: Wed, 28 Feb 2024 15:27:31 -0800 Subject: [PATCH 4/5] skip iso test on windows --- geosnap/tests/test_isochrones.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/geosnap/tests/test_isochrones.py b/geosnap/tests/test_isochrones.py index 917d051b..fcf49405 100644 --- a/geosnap/tests/test_isochrones.py +++ b/geosnap/tests/test_isochrones.py @@ -21,14 +21,14 @@ def get_data(): return example_origin, sd_network - +@pytest.mark.skipif(sys.platform.startswith("win"), reason="skipping test on windows because of dtype issue") @pytest.mark.xdist_group(name="group1") def test_isos_from_ids(): example_origin, sd_network = get_data() iso = isochrones_from_id(example_origin, sd_network, threshold=1600) assert_almost_equal(iso.area.round(6).astype(float).tolist()[0], 0.000128) - +@pytest.mark.skipif(sys.platform.startswith("win"), reason="skipping test on windows because of dtype issue") @pytest.mark.xdist_group(name="group1") def test_isos_from_gdf(): example_origin, sd_network = get_data() From 0454e8baf0100d07847d91161e8300916de2da25 Mon Sep 17 00:00:00 2001 From: eli knaap Date: Wed, 28 Feb 2024 15:28:12 -0800 Subject: [PATCH 5/5] import sys --- geosnap/tests/test_isochrones.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/geosnap/tests/test_isochrones.py b/geosnap/tests/test_isochrones.py index fcf49405..add3b906 100644 --- a/geosnap/tests/test_isochrones.py +++ b/geosnap/tests/test_isochrones.py @@ -7,6 +7,7 @@ import geopandas as gpd import os import pytest +import sys from numpy.testing import assert_almost_equal @@ -21,14 +22,22 @@ def get_data(): return example_origin, sd_network -@pytest.mark.skipif(sys.platform.startswith("win"), reason="skipping test on windows because of dtype issue") + +@pytest.mark.skipif( + sys.platform.startswith("win"), + reason="skipping test on windows because of dtype issue", +) @pytest.mark.xdist_group(name="group1") def test_isos_from_ids(): example_origin, sd_network = get_data() iso = isochrones_from_id(example_origin, sd_network, threshold=1600) assert_almost_equal(iso.area.round(6).astype(float).tolist()[0], 0.000128) -@pytest.mark.skipif(sys.platform.startswith("win"), reason="skipping test on windows because of dtype issue") + +@pytest.mark.skipif( + sys.platform.startswith("win"), + reason="skipping test on windows because of dtype issue", +) @pytest.mark.xdist_group(name="group1") def test_isos_from_gdf(): example_origin, sd_network = get_data()