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

Deprecate scipy sparse matrix conversion functions #5262

Merged
merged 3 commits into from Jan 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/developer/deprecations.rst
Expand Up @@ -99,3 +99,5 @@ Version 3.0
* In ``networkx/algorithms/link_analysis/pagerank_alg.py``, remove the
``np.asmatrix`` wrappers on the return values of ``google_matrix`` and remove
the associated FutureWarning.
* In ``networkx/convert_matrix.py`` remove ``from_scipy_sparse_matrix`` and
``to_scipy_sparse_matrix``.
3 changes: 3 additions & 0 deletions doc/release/release_dev.rst
Expand Up @@ -59,6 +59,9 @@ Deprecations
Deprecate ``euclidean`` in favor of ``math.dist``.
- [`#5166 <https://github.com/networkx/networkx/pull/5166>`_]
Deprecate the ``hmn`` and ``lgc`` modules in ``node_classification``.
- [`#5262 <https://github.com/networkx/networkx/pull/5262>`_]
Deprecate ``to_scipy_sparse_matrix`` and ``from_scipy_sparse_matrix`` in
favor of ``to_scipy_sparse_array`` and ``from_scipy_sparse_array``, respectively.


Merged PRs
Expand Down
5 changes: 5 additions & 0 deletions networkx/conftest.py
Expand Up @@ -214,6 +214,11 @@ def set_warnings():
warnings.filterwarnings(
"ignore", category=FutureWarning, message="adjacency_matrix"
)
warnings.filterwarnings(
"ignore",
category=DeprecationWarning,
message="\n\nThe scipy.sparse array containers",
)


@pytest.fixture(autouse=True)
Expand Down
16 changes: 16 additions & 0 deletions networkx/convert_matrix.py
Expand Up @@ -987,6 +987,14 @@ def to_scipy_sparse_matrix(G, nodelist=None, dtype=None, weight="weight", format
import scipy as sp
import scipy.sparse

warnings.warn(
(
"\n\nThe scipy.sparse array containers will be used instead of matrices\n"
"in Networkx 3.0. Use `to_scipy_sparse_array` instead."
),
DeprecationWarning,
stacklevel=2,
)
A = to_scipy_sparse_array(
G, nodelist=nodelist, dtype=dtype, weight=weight, format=format
)
Expand Down Expand Up @@ -1061,6 +1069,14 @@ def from_scipy_sparse_matrix(
AtlasView({0: {'weight': 1}, 1: {'weight': 1}})

"""
warnings.warn(
(
"\n\nThe scipy.sparse array containers will be used instead of matrices\n"
"in Networkx 3.0. Use `from_scipy_sparse_array` instead."
),
DeprecationWarning,
stacklevel=2,
)
return from_scipy_sparse_array(
A,
parallel_edges=parallel_edges,
Expand Down
10 changes: 10 additions & 0 deletions networkx/tests/test_convert_scipy.py
Expand Up @@ -281,3 +281,13 @@ def test_from_scipy_sparse_array_formats(sparse_format):
)
A = sp.sparse.coo_array([[0, 3, 2], [3, 0, 1], [2, 1, 0]]).asformat(sparse_format)
assert graphs_equal(expected, nx.from_scipy_sparse_array(A))


# NOTE: remove when to/from_sparse_matrix deprecations expire
def test_scipy_sparse_matrix_deprecations():
G = nx.path_graph(3)
msg = "\n\nThe scipy.sparse array containers will be used instead of matrices"
with pytest.warns(DeprecationWarning, match=msg):
M = nx.to_scipy_sparse_matrix(G)
with pytest.warns(DeprecationWarning, match=msg):
H = nx.from_scipy_sparse_matrix(M)