Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove previously deprecated functionality #1113

Merged
merged 30 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f04cb5e
update deprecation warning message to note that deprecated code will …
gboeing Jan 16, 2024
8c5999c
update changelog
gboeing Jan 16, 2024
c25f083
Merge pull request #1111 from gboeing/dep
gboeing Jan 16, 2024
b5ebda4
dev version
gboeing Jan 16, 2024
f15310d
update changelog
gboeing Jan 16, 2024
c993367
deprecate north, south, east, west arguments throughout package in fa…
gboeing Jan 16, 2024
c406dc4
Merge branch 'main' into bbox
gboeing Jan 16, 2024
aa07978
increase test coverage
gboeing Jan 16, 2024
ca2bed0
Merge pull request #1112 from gboeing/bbox
gboeing Jan 16, 2024
d0c2883
merge main into dep
gboeing Jan 16, 2024
7deae0b
remove deprecated north, south, east, west function parameters throug…
gboeing Jan 16, 2024
894e794
remove deprecated save_graph_shapfile function
gboeing Jan 16, 2024
80511bc
remove deprecated get_route_edge_attributes function
gboeing Jan 16, 2024
9b5cc09
remove deprecated config function
gboeing Jan 16, 2024
87bbe76
remove round_geometry_coords function
gboeing Jan 16, 2024
122fe0c
remove deprecated folium and geometries modules
gboeing Jan 16, 2024
2855e5c
remove deprecated plot_orientation function that had moved to plot mo…
gboeing Jan 16, 2024
7511941
remove deprecated save_graph_xml function that had moved to io module…
gboeing Jan 16, 2024
f01566f
fix docs
gboeing Jan 16, 2024
fb4f904
remove deprecated functions from distance module
gboeing Jan 16, 2024
8f6880e
remove deprecated return_hex param from get_colors function
gboeing Jan 17, 2024
0712968
remove precision and other deprecated function params
gboeing Jan 17, 2024
663dc75
remove deprecated buffer_dist, clean_periphery, interpolate, return_c…
gboeing Jan 17, 2024
74d0ac6
update changelog
gboeing Jan 17, 2024
9c1ac17
change Generator return type to Iterator
gboeing Jan 17, 2024
7bdfc41
fix docstring
gboeing Jan 17, 2024
fceee44
consume generator to increase test coverage
gboeing Jan 17, 2024
3e8df7a
code cleanup
gboeing Jan 17, 2024
845d32b
improve warning messages
gboeing Jan 17, 2024
fb9cc5e
increase test coverage
gboeing Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
## 2.0.0 (Unreleased)

- add type annotations throughout the package for user type hinting and type checking (#1107)
- remove functionality previously deprecated in v1 (#1113)

## 1.x.x (Unreleased)
## 1.9.0 (Unreleased)

- fix a bug in the features module's polygon handling (#1104)
- update obsolete numpy random number generation (#1108)
- update warning messages to note that deprecated code will be removed in v2.0.0 (#1111)
- deprecate north, south, east, west arguments throughout package in favor of bbox tuple argument (#1112)
- deprecate return_coords argument in graph.graph_from_address function (#1105)
- deprecate return_hex argument in plot.get_colors function (#1109)

Expand Down
22 changes: 3 additions & 19 deletions docs/source/internals-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ osmnx.features module
:private-members:
:noindex:

osmnx.folium module
-------------------

.. automodule:: osmnx.folium
:members:
:private-members:
:noindex:

osmnx.geocoder module
---------------------

Expand All @@ -75,14 +67,6 @@ osmnx.geocoder module
:private-members:
:noindex:

osmnx.geometries module
-----------------------

.. automodule:: osmnx.geometries
:members:
:private-members:
:noindex:

osmnx.graph module
------------------

Expand All @@ -107,10 +91,10 @@ osmnx._nominatim module
:private-members:
:noindex:

osmnx.osm_xml module
--------------------
osmnx._osm_xml module
---------------------

.. automodule:: osmnx.osm_xml
.. automodule:: osmnx._osm_xml
:members:
:private-members:
:noindex:
Expand Down
10 changes: 0 additions & 10 deletions osmnx/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@
from .features import features_from_point
from .features import features_from_polygon
from .features import features_from_xml
from .folium import plot_graph_folium
from .folium import plot_route_folium
from .geocoder import geocode
from .geocoder import geocode_to_gdf
from .geometries import geometries_from_address
from .geometries import geometries_from_bbox
from .geometries import geometries_from_place
from .geometries import geometries_from_point
from .geometries import geometries_from_polygon
from .geometries import geometries_from_xml
from .graph import graph_from_address
from .graph import graph_from_bbox
from .graph import graph_from_place
Expand All @@ -32,7 +24,6 @@
from .graph import graph_from_xml
from .io import load_graphml
from .io import save_graph_geopackage
from .io import save_graph_shapefile
from .io import save_graph_xml
from .io import save_graphml
from .plot import plot_figure_ground
Expand All @@ -51,7 +42,6 @@
from .speed import add_edge_travel_times
from .stats import basic_stats
from .utils import citation
from .utils import config
from .utils import log
from .utils import ts
from .utils_graph import get_digraph
Expand Down
84 changes: 7 additions & 77 deletions osmnx/osm_xml.py → osmnx/_osm_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ def _opener(filepath: Path, encoding: str) -> TextIO:
with _opener(Path(filepath), encoding) as f:
root_attrs = ET.parse(f).getroot().attrib
if "generator" in root_attrs and "OSMnx" in root_attrs["generator"]:
warn(
msg = (
"The XML file you are loading appears to have been generated "
"by OSMnx: this use case is not supported and may not behave "
"as expected. To save/load graphs to/from disk for later use "
"in OSMnx, use the `io.save_graphml` and `io.load_graphml` "
"functions instead. Refer to the documentation for details.",
stacklevel=2,
"functions instead. Refer to the documentation for details."
)
warn(msg, stacklevel=2)

# parse the XML to Overpass-like JSON
with _opener(Path(filepath), encoding) as f:
Expand All @@ -112,76 +112,6 @@ def _opener(filepath: Path, encoding: str) -> TextIO:
return handler.object


def save_graph_xml( # type: ignore[no-untyped-def]
data,
filepath=None,
node_tags=settings.osm_xml_node_tags,
node_attrs=settings.osm_xml_node_attrs,
edge_tags=settings.osm_xml_way_tags,
edge_attrs=settings.osm_xml_way_attrs,
oneway=False,
merge_edges=True,
edge_tag_aggs=None,
api_version="0.6",
precision=6,
):
"""
Do not use: deprecated.

The `save_graph_xml` has moved from the `osm_xml` module to the `io`
module. `osm_xml.save_graph_xml` has been deprecated and will be removed
in a future release. Access the function via the `io` module instead.

Parameters
----------
data : networkx.multidigraph
do not use, deprecated
filepath : string or pathlib.Path
do not use, deprecated
node_tags : list
do not use, deprecated
node_attrs: list
do not use, deprecated
edge_tags : list
do not use, deprecated
edge_attrs : list
do not use, deprecated
oneway : bool
do not use, deprecated
merge_edges : bool
do not use, deprecated
edge_tag_aggs : list of length-2 string tuples
do not use, deprecated
api_version : str
do not use, deprecated
precision : int
do not use, deprecated

Returns
-------
None
"""
warn(
"The save_graph_xml function has moved from the osm_xml module to the io module. "
" osm_xml.save_graph_xml has been deprecated and will be removed in a "
" future release. Access the function via the io module instead.",
stacklevel=2,
)
_save_graph_xml(
data,
filepath,
node_tags,
node_attrs,
edge_tags,
edge_attrs,
oneway,
merge_edges,
edge_tag_aggs,
api_version,
precision,
)


def _save_graph_xml(
data: nx.MultiDiGraph | tuple[gpd.GeoDataFrame, gpd.GeoDataFrame],
filepath: str | Path | None,
Expand Down Expand Up @@ -244,12 +174,12 @@ def _save_graph_xml(
# if save folder does not already exist, create it
filepath.parent.mkdir(parents=True, exist_ok=True)

if not settings.all_oneway: # pragma: no cover
warn(
if not settings.all_oneway:
msg = (
"For the `save_graph_xml` function to behave properly, the graph "
"must have been created with `ox.settings.all_oneway=True`.",
stacklevel=2,
"must have been created with `ox.settings.all_oneway=True`."
)
warn(msg, stacklevel=2)

if isinstance(data, nx.MultiDiGraph):
gdf_nodes, gdf_edges = utils_graph.graph_to_gdfs(
Expand Down
10 changes: 5 additions & 5 deletions osmnx/_overpass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging as lg
import time
from collections import OrderedDict
from collections.abc import Generator
from collections.abc import Iterator
from typing import Any

import numpy as np
Expand Down Expand Up @@ -148,9 +148,9 @@ def _get_overpass_pause(
)
status = response.text.split("\n")[4]
status_first_token = status.split(" ")[0]
except ConnectionError: # pragma: no cover
except ConnectionError as ce: # pragma: no cover
# cannot reach status endpoint, log error and return default duration
utils.log(f"Unable to query {url}, got status {response.status_code}", level=lg.ERROR)
utils.log(f"Unable to query {url}, {ce}", level=lg.ERROR)
return default_duration
except (AttributeError, IndexError, ValueError): # pragma: no cover
# cannot parse output, log error and return default duration
Expand Down Expand Up @@ -305,7 +305,7 @@ def _create_overpass_query(polygon_coord_str: str, tags: dict[str, bool | str |

def _download_overpass_network(
polygon: Polygon | MultiPolygon, network_type: str, custom_filter: str | None
) -> Generator[dict[str, Any], None, None]:
) -> Iterator[dict[str, Any]]:
"""
Retrieve networked ways and nodes within boundary from the Overpass API.

Expand Down Expand Up @@ -343,7 +343,7 @@ def _download_overpass_network(

def _download_overpass_features(
polygon: Polygon, tags: dict[str, bool | str | list[str]]
) -> Generator[dict[str, Any], None, None]:
) -> Iterator[dict[str, Any]]:
"""
Retrieve OSM features within some boundary polygon from the Overpass API.

Expand Down
101 changes: 2 additions & 99 deletions osmnx/bearing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
from __future__ import annotations

from typing import overload
from warnings import warn

import networkx as nx
import numpy as np
from numpy.typing import NDArray

from . import plot
from . import projection

# scipy is an optional dependency for entropy calculation
Expand Down Expand Up @@ -85,7 +83,7 @@ def calculate_bearing(
return bearing


def add_edge_bearings(G: nx.MultiDiGraph, precision: int | None = None) -> nx.MultiDiGraph:
def add_edge_bearings(G: nx.MultiDiGraph) -> nx.MultiDiGraph:
"""
Add compass `bearing` attributes to all graph edges.

Expand All @@ -100,22 +98,12 @@ def add_edge_bearings(G: nx.MultiDiGraph, precision: int | None = None) -> nx.Mu
----------
G : networkx.MultiDiGraph
unprojected graph
precision : int
deprecated, do not use

Returns
-------
G : networkx.MultiDiGraph
graph with edge bearing attributes
"""
if precision is None:
precision = 1
else:
warn(
"the `precision` parameter is deprecated and will be removed in a future release",
stacklevel=2,
)

if projection.is_projected(G.graph["crs"]): # pragma: no cover
msg = "graph must be unprojected to add edge bearings"
raise ValueError(msg)
Expand All @@ -128,7 +116,7 @@ def add_edge_bearings(G: nx.MultiDiGraph, precision: int | None = None) -> nx.Mu

# calculate bearings then set as edge attributes
bearings = calculate_bearing(coords[:, 0], coords[:, 1], coords[:, 2], coords[:, 3])
values = zip(uvk, bearings.round(precision))
values = zip(uvk, bearings)
nx.set_edge_attributes(G, dict(values), name="bearing")

return G
Expand Down Expand Up @@ -272,88 +260,3 @@ def _bearings_distribution(
# because we merged the bins, their edges are now only every other one
bin_edges = bin_edges[range(0, len(bin_edges), 2)]
return bin_counts, bin_edges


def plot_orientation( # type: ignore[no-untyped-def]
Gu,
num_bins=36,
min_length=0,
weight=None,
ax=None,
figsize=(5, 5),
area=True,
color="#003366",
edgecolor="k",
linewidth=0.5,
alpha=0.7,
title=None,
title_y=1.05,
title_font=None,
xtick_font=None,
):
"""
Do not use: deprecated.

The plot_orientation function moved to the plot module. Calling it via the
bearing module will raise an error in a future release.

Parameters
----------
Gu : networkx.MultiGraph
deprecated, do not use
num_bins : int
deprecated, do not use
min_length : float
deprecated, do not use
weight : string
deprecated, do not use
ax : matplotlib.axes.PolarAxesSubplot
deprecated, do not use
figsize : tuple
deprecated, do not use
area : bool
deprecated, do not use
color : string
deprecated, do not use
edgecolor : string
deprecated, do not use
linewidth : float
deprecated, do not use
alpha : float
deprecated, do not use
title : string
deprecated, do not use
title_y : float
deprecated, do not use
title_font : dict
deprecated, do not use
xtick_font : dict
deprecated, do not use

Returns
-------
fig, ax : tuple
matplotlib figure, axis
"""
warn(
"The `plot_orientation` function moved to the `plot` module. Calling it "
"via the `bearing` module will cause an exception in a future release.",
stacklevel=2,
)
return plot.plot_orientation(
Gu,
num_bins=num_bins,
min_length=min_length,
weight=weight,
ax=ax,
figsize=figsize,
area=area,
color=color,
edgecolor=edgecolor,
linewidth=linewidth,
alpha=alpha,
title=title,
title_y=title_y,
title_font=title_font,
xtick_font=xtick_font,
)
Loading