Skip to content

Remove deprecated to_values and from_values. #529

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

Merged
merged 2 commits into from
Dec 17, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions graphblas/core/automethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,6 @@ def to_edgelist(self):
return self._get_value("to_edgelist")


def to_values(self):
return self._get_value("to_values")


def value(self):
return self._get_value("value")

Expand Down Expand Up @@ -398,7 +394,6 @@ def _main():
"ss",
"to_coo",
"to_dense",
"to_values",
}
vector = {
"_as_matrix",
Expand Down
2 changes: 0 additions & 2 deletions graphblas/core/infix.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ def dup(self, dtype=None, *, clear=False, mask=None, name=None, **opts):
to_coo = wrapdoc(Vector.to_coo)(property(automethods.to_coo))
to_dense = wrapdoc(Vector.to_dense)(property(automethods.to_dense))
to_dict = wrapdoc(Vector.to_dict)(property(automethods.to_dict))
to_values = wrapdoc(Vector.to_values)(property(automethods.to_values))
vxm = wrapdoc(Vector.vxm)(property(automethods.vxm))
wait = wrapdoc(Vector.wait)(property(automethods.wait))
# These raise exceptions
Expand Down Expand Up @@ -396,7 +395,6 @@ def dup(self, dtype=None, *, clear=False, mask=None, name=None, **opts):
to_dense = wrapdoc(Matrix.to_dense)(property(automethods.to_dense))
to_dicts = wrapdoc(Matrix.to_dicts)(property(automethods.to_dicts))
to_edgelist = wrapdoc(Matrix.to_edgelist)(property(automethods.to_edgelist))
to_values = wrapdoc(Matrix.to_values)(property(automethods.to_values))
wait = wrapdoc(Matrix.wait)(property(automethods.wait))
# These raise exceptions
__array__ = Matrix.__array__
Expand Down
101 changes: 0 additions & 101 deletions graphblas/core/matrix.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
import warnings
from collections.abc import Sequence

import numpy as np
Expand Down Expand Up @@ -515,42 +514,6 @@ def resize(self, nrows, ncols):
self._nrows = nrows.value
self._ncols = ncols.value

def to_values(self, dtype=None, *, rows=True, columns=True, values=True, sort=True):
"""Extract the indices and values as a 3-tuple of numpy arrays
corresponding to the COO format of the Matrix.

.. deprecated:: 2022.11.0
``Matrix.to_values`` will be removed in a future release.
Use ``Matrix.to_coo`` instead. Will be removed in version 2023.9.0 or later

Parameters
----------
dtype :
Requested dtype for the output values array.
rows : bool, default=True
Whether to return rows; will return ``None`` for rows if ``False``
columns : bool, default=True
Whether to return columns; will return ``None`` for columns if ``False``
values : bool, default=True
Whether to return values; will return ``None`` for values if ``False``
sort : bool, default=True
Whether to require sorted indices.
If internally stored rowwise, the sorting will be first by rows, then by column.
If internally stored columnwise, the sorting will be first by column, then by row.

Returns
-------
np.ndarray[dtype=uint64] : Rows
np.ndarray[dtype=uint64] : Columns
np.ndarray : Values
"""
warnings.warn(
"`Matrix.to_values(...)` is deprecated; please use `Matrix.to_coo(...)` instead.",
DeprecationWarning,
stacklevel=2,
)
return self.to_coo(dtype, rows=rows, columns=columns, values=values, sort=sort)

def to_coo(self, dtype=None, *, rows=True, columns=True, values=True, sort=True):
"""Extract the indices and values as a 3-tuple of numpy arrays
corresponding to the COO format of the Matrix.
Expand Down Expand Up @@ -837,61 +800,6 @@ def get(self, row, col, default=None):
"Indices should get a single element, which will be extracted as a Python scalar."
)

@classmethod
def from_values(
cls,
rows,
columns,
values,
dtype=None,
*,
nrows=None,
ncols=None,
dup_op=None,
name=None,
):
"""Create a new Matrix from row and column indices and values.

.. deprecated:: 2022.11.0
``Matrix.from_values`` will be removed in a future release.
Use ``Matrix.from_coo`` instead. Will be removed in version 2023.9.0 or later

Parameters
----------
rows : list or np.ndarray
Row indices.
columns : list or np.ndarray
Column indices.
values : list or np.ndarray or scalar
List of values. If a scalar is provided, all values will be set to this single value.
dtype :
Data type of the Matrix. If not provided, the values will be inspected
to choose an appropriate dtype.
nrows : int, optional
Number of rows in the Matrix. If not provided, ``nrows`` is computed
from the maximum row index found in ``rows``.
ncols : int, optional
Number of columns in the Matrix. If not provided, ``ncols`` is computed
from the maximum column index found in ``columns``.
dup_op : :class:`~graphblas.core.operator.BinaryOp`, optional
Function used to combine values if duplicate indices are found.
Leaving ``dup_op=None`` will raise an error if duplicates are found.
name : str, optional
Name to give the Matrix.

Returns
-------
Matrix
"""
warnings.warn(
"`Matrix.from_values(...)` is deprecated; please use `Matrix.from_coo(...)` instead.",
DeprecationWarning,
stacklevel=2,
)
return cls.from_coo(
rows, columns, values, dtype, nrows=nrows, ncols=ncols, dup_op=dup_op, name=name
)

@classmethod
def from_coo(
cls,
Expand Down Expand Up @@ -3751,7 +3659,6 @@ def dup(self, dtype=None, *, clear=False, mask=None, name=None, **opts):
to_dense = wrapdoc(Matrix.to_dense)(property(automethods.to_dense))
to_dicts = wrapdoc(Matrix.to_dicts)(property(automethods.to_dicts))
to_edgelist = wrapdoc(Matrix.to_edgelist)(property(automethods.to_edgelist))
to_values = wrapdoc(Matrix.to_values)(property(automethods.to_values))
wait = wrapdoc(Matrix.wait)(property(automethods.wait))
# These raise exceptions
__array__ = Matrix.__array__
Expand Down Expand Up @@ -3852,7 +3759,6 @@ def dup(self, dtype=None, *, clear=False, mask=None, name=None, **opts):
to_dense = wrapdoc(Matrix.to_dense)(property(automethods.to_dense))
to_dicts = wrapdoc(Matrix.to_dicts)(property(automethods.to_dicts))
to_edgelist = wrapdoc(Matrix.to_edgelist)(property(automethods.to_edgelist))
to_values = wrapdoc(Matrix.to_values)(property(automethods.to_values))
wait = wrapdoc(Matrix.wait)(property(automethods.wait))
# These raise exceptions
__array__ = Matrix.__array__
Expand Down Expand Up @@ -3927,13 +3833,6 @@ def to_coo(self, dtype=None, *, rows=True, columns=True, values=True, sort=True)
)
return cols, rows, vals

@wrapdoc(Matrix.to_values)
def to_values(self, dtype=None, *, rows=True, columns=True, values=True, sort=True):
rows, cols, vals = self._matrix.to_values(
dtype, rows=rows, columns=columns, values=values, sort=sort
)
return cols, rows, vals

@wrapdoc(Matrix.diag)
def diag(self, k=0, dtype=None, *, name=None, **opts):
return self._matrix.diag(-k, dtype, name=name, **opts)
Expand Down
70 changes: 0 additions & 70 deletions graphblas/core/vector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import itertools
import warnings

import numpy as np

Expand Down Expand Up @@ -456,36 +455,6 @@ def resize(self, size):
call("GrB_Vector_resize", [self, size])
self._size = size.value

def to_values(self, dtype=None, *, indices=True, values=True, sort=True):
"""Extract the indices and values as a 2-tuple of numpy arrays.

.. deprecated:: 2022.11.0
``Vector.to_values`` will be removed in a future release.
Use ``Vector.to_coo`` instead. Will be removed in version 2023.9.0 or later

Parameters
----------
dtype :
Requested dtype for the output values array.
indices :bool, default=True
Whether to return indices; will return ``None`` for indices if ``False``
values : bool, default=True
Whether to return values; will return ``None`` for values if ``False``
sort : bool, default=True
Whether to require sorted indices.

Returns
-------
np.ndarray[dtype=uint64] : Indices
np.ndarray : Values
"""
warnings.warn(
"`Vector.to_values(...)` is deprecated; please use `Vector.to_coo(...)` instead.",
DeprecationWarning,
stacklevel=2,
)
return self.to_coo(dtype, indices=indices, values=values, sort=sort)

def to_coo(self, dtype=None, *, indices=True, values=True, sort=True):
"""Extract the indices and values as a 2-tuple of numpy arrays.

Expand Down Expand Up @@ -697,43 +666,6 @@ def get(self, index, default=None):
"A single index should be given, and the result will be a Python scalar."
)

@classmethod
def from_values(cls, indices, values, dtype=None, *, size=None, dup_op=None, name=None):
"""Create a new Vector from indices and values.

.. deprecated:: 2022.11.0
``Vector.from_values`` will be removed in a future release.
Use ``Vector.from_coo`` instead. Will be removed in version 2023.9.0 or later

Parameters
----------
indices : list or np.ndarray
Vector indices.
values : list or np.ndarray or scalar
List of values. If a scalar is provided, all values will be set to this single value.
dtype :
Data type of the Vector. If not provided, the values will be inspected
to choose an appropriate dtype.
size : int, optional
Size of the Vector. If not provided, ``size`` is computed from
the maximum index found in ``indices``.
dup_op : BinaryOp, optional
Function used to combine values if duplicate indices are found.
Leaving ``dup_op=None`` will raise an error if duplicates are found.
name : str, optional
Name to give the Vector.

Returns
-------
Vector
"""
warnings.warn(
"`Vector.from_values(...)` is deprecated; please use `Vector.from_coo(...)` instead.",
DeprecationWarning,
stacklevel=2,
)
return cls.from_coo(indices, values, dtype, size=size, dup_op=dup_op, name=name)

@classmethod
def from_coo(cls, indices, values=1.0, dtype=None, *, size=None, dup_op=None, name=None):
"""Create a new Vector from indices and values.
Expand Down Expand Up @@ -2271,7 +2203,6 @@ def dup(self, dtype=None, *, clear=False, mask=None, name=None, **opts):
to_coo = wrapdoc(Vector.to_coo)(property(automethods.to_coo))
to_dense = wrapdoc(Vector.to_dense)(property(automethods.to_dense))
to_dict = wrapdoc(Vector.to_dict)(property(automethods.to_dict))
to_values = wrapdoc(Vector.to_values)(property(automethods.to_values))
vxm = wrapdoc(Vector.vxm)(property(automethods.vxm))
wait = wrapdoc(Vector.wait)(property(automethods.wait))
# These raise exceptions
Expand Down Expand Up @@ -2359,7 +2290,6 @@ def dup(self, dtype=None, *, clear=False, mask=None, name=None, **opts):
to_coo = wrapdoc(Vector.to_coo)(property(automethods.to_coo))
to_dense = wrapdoc(Vector.to_dense)(property(automethods.to_dense))
to_dict = wrapdoc(Vector.to_dict)(property(automethods.to_dict))
to_values = wrapdoc(Vector.to_values)(property(automethods.to_values))
vxm = wrapdoc(Vector.vxm)(property(automethods.vxm))
wait = wrapdoc(Vector.wait)(property(automethods.wait))
# These raise exceptions
Expand Down
11 changes: 0 additions & 11 deletions graphblas/tests/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2952,7 +2952,6 @@ def test_expr_is_like_matrix(A):
"from_dicts",
"from_edgelist",
"from_scalar",
"from_values",
"resize",
"setdiag",
"update",
Expand Down Expand Up @@ -3018,7 +3017,6 @@ def test_index_expr_is_like_matrix(A):
"from_dicts",
"from_edgelist",
"from_scalar",
"from_values",
"resize",
"setdiag",
}
Expand Down Expand Up @@ -3557,15 +3555,6 @@ def compare(A, expected, isequal=True, **kwargs):
A.ss.compactify("bad_how")


def test_deprecated(A):
with pytest.warns(DeprecationWarning):
A.to_values()
with pytest.warns(DeprecationWarning):
A.T.to_values()
with pytest.warns(DeprecationWarning):
A.from_values([1], [2], [3])


def test_ndim(A):
assert A.ndim == 2
assert A.ewise_mult(A).ndim == 2
Expand Down
9 changes: 0 additions & 9 deletions graphblas/tests/test_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,6 @@ def test_expr_is_like_vector(v):
"from_dict",
"from_pairs",
"from_scalar",
"from_values",
"resize",
"update",
}
Expand Down Expand Up @@ -1725,7 +1724,6 @@ def test_index_expr_is_like_vector(v):
"from_dict",
"from_pairs",
"from_scalar",
"from_values",
"resize",
}
ignore = {"__sizeof__", "_ewise_add", "_ewise_mult", "_ewise_union", "_inner", "_vxm"}
Expand Down Expand Up @@ -2012,13 +2010,6 @@ def test_ss_split(v):
assert x2.name == "split_1"


def test_deprecated(v):
with pytest.warns(DeprecationWarning):
v.to_values()
with pytest.warns(DeprecationWarning):
Vector.from_values([1], [2])


def test_ndim(A, v):
assert v.ndim == 1
assert v.ewise_mult(v).ndim == 1
Expand Down