Skip to content

Commit

Permalink
Merge pull request #1089 from gboeing/release
Browse files Browse the repository at this point in the history
resolve deprecation warnings
  • Loading branch information
gboeing authored Nov 27, 2023
2 parents 60a28a7 + 99e53a1 commit 4209c12
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- formally support Python 3.12 (#1082)
- fix Windows-specific character encoding issue when reading XML files (#1084)
- resolve pandas and gdal future warnings (#1089)
- use spawn instead of fork for multiprocessing to resolve Python 3.12 deprecation warning (#1089)
- rename add_node_elevations_google function's max_locations_per_batch parameter, with deprecation warning (#1088)
- move add_node_elevations_google function's url_template parameter to settings module, with deprecation warning (#1088)

Expand Down
8 changes: 3 additions & 5 deletions osmnx/elevation.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def add_node_elevations_raster(G, filepath, band=1, cpus=None):
filepaths = [str(p) for p in filepath]
sha = sha1(str(filepaths).encode("utf-8")).hexdigest()
filepath = f"./.osmnx_{sha}.vrt"
gdal.UseExceptions()
gdal.BuildVRT(filepath, filepaths).FlushCache()

nodes = utils_graph.graph_to_gdfs(G, edges=False, node_geometry=False)[["x", "y"]]
Expand All @@ -148,11 +149,8 @@ def add_node_elevations_raster(G, filepath, band=1, cpus=None):
# divide nodes into equal-sized chunks for multiprocessing
size = int(np.ceil(len(nodes) / cpus))
args = ((nodes.iloc[i : i + size], filepath, band) for i in range(0, len(nodes), size))
pool = mp.Pool(cpus)
sma = pool.starmap_async(_query_raster, args)
results = sma.get()
pool.close()
pool.join()
with mp.get_context("spawn").Pool(cpus) as pool:
results = pool.starmap_async(_query_raster, args).get()
elevs = {k: v for kv in results for k, v in kv}

assert len(G) == len(elevs)
Expand Down
2 changes: 1 addition & 1 deletion osmnx/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def features_from_place(query, tags, which_result=None, buffer_dist=None):
"""
if buffer_dist is not None:
warn(
"The buffer_dist argument as been deprecated and will be removed "
"The buffer_dist argument has been deprecated and will be removed "
"in a future release. Buffer your query area directly, if desired.",
stacklevel=2,
)
Expand Down
2 changes: 1 addition & 1 deletion osmnx/geocoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def geocode_to_gdf(query, which_result=None, by_osmid=False, buffer_dist=None):
"""
if buffer_dist is not None:
warn(
"The buffer_dist argument as been deprecated and will be removed "
"The buffer_dist argument has been deprecated and will be removed "
"in a future release. Buffer your results directly, if desired.",
stacklevel=2,
)
Expand Down
2 changes: 1 addition & 1 deletion osmnx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def graph_from_place(
"""
if buffer_dist is not None:
warn(
"The buffer_dist argument as been deprecated and will be removed "
"The buffer_dist argument has been deprecated and will be removed "
"in a future release. Buffer your query area directly, if desired.",
stacklevel=2,
)
Expand Down
7 changes: 2 additions & 5 deletions osmnx/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ def shortest_path(G, orig, dest, weight="length", cpus=1):
# if multi-threading, calculate shortest paths in parallel
else:
args = ((G, o, d, weight) for o, d in zip(orig, dest))
pool = mp.Pool(cpus)
sma = pool.starmap_async(_single_shortest_path, args)
paths = sma.get()
pool.close()
pool.join()
with mp.get_context("spawn").Pool(cpus) as pool:
paths = pool.starmap_async(_single_shortest_path, args).get()

return paths

Expand Down
3 changes: 2 additions & 1 deletion osmnx/simplification.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,11 @@ def _consolidate_intersections_rebuild_graph(G, tolerance=10, reconnect_edges=Tr
# STEP 2
# attach each node to its cluster of merged nodes. first get the original
# graph's node points then spatial join to give each node the label of
# cluster it's within
# cluster it's within. make cluster labels type string.
node_points = utils_graph.graph_to_gdfs(G, edges=False)[["geometry"]]
gdf = gpd.sjoin(node_points, node_clusters, how="left", predicate="within")
gdf = gdf.drop(columns="geometry").rename(columns={"index_right": "cluster"})
gdf["cluster"] = gdf["cluster"].astype(str)

# STEP 3
# if a cluster contains multiple components (i.e., it's not connected)
Expand Down

0 comments on commit 4209c12

Please sign in to comment.