Skip to content

Commit

Permalink
Corrected deprecation warnings (#1019)
Browse files Browse the repository at this point in the history
* Editing contributing guidelines 

My edits were based on my experience with getting set up on GitHub. I added some minor changes of things I wish I had read while I was trying to set up my account.

* fix typo

* Resolving two deprecation warnings

* Removing IDAD tests

* Correcting some deprecation errors

* Correcting more deprecation warnings

* Revert "Removing IDAD tests"
Moving commit to the correct location

This reverts commit 00a2e76.

* Correcting formatting errors:

---------

Co-authored-by: Benjamin Pedigo <[email protected]>
Co-authored-by: hugwuoke <[email protected]>
  • Loading branch information
3 people committed Mar 23, 2023
1 parent d797406 commit 7e346cf
Show file tree
Hide file tree
Showing 21 changed files with 26 additions and 38 deletions.
1 change: 0 additions & 1 deletion graspologic/align/orthogonal_procrustes.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class OrthogonalProcrustes(BaseAlign):
def __init__(
self,
) -> None:

super().__init__()

def fit(self, X: np.ndarray, Y: np.ndarray) -> "OrthogonalProcrustes":
Expand Down
1 change: 0 additions & 1 deletion graspologic/cluster/divisive_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ def __init__(
max_level: int = 4,
delta_criter: float = 0,
):

_check_common_inputs(min_components, max_components, cluster_kws)

if cluster_method not in ["gmm", "kmeans"]:
Expand Down
1 change: 0 additions & 1 deletion graspologic/match/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ def _compare_dimensions(
def _check_partial_match(
partial_match: Optional[Union[np.ndarray, Tuple]], n1: int, n2: int
) -> np.ndarray:

_partial_match: np.ndarray
if partial_match is None:
_partial_match = np.array([[], []]).T
Expand Down
1 change: 0 additions & 1 deletion graspologic/models/edge_swaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class EdgeSwapper:

@beartype
def __init__(self, adjacency: AdjacencyMatrix, seed: Optional[int] = None):

weight_check = is_unweighted(adjacency)
check_argument(weight_check, "adjacency must be unweighted")

Expand Down
1 change: 0 additions & 1 deletion graspologic/nominate/spectralVN.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def _check_y(self, y: np.ndarray) -> None:
)

def _check_params(self) -> None:

if self.n_neighbors is not None and type(self.n_neighbors) is not int:
raise TypeError("k must be an integer")
elif self.n_neighbors is not None and self.n_neighbors <= 0:
Expand Down
5 changes: 2 additions & 3 deletions graspologic/partition/leiden.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _community_python_to_native(
if starting_communities is None:
return None
native_safe: Dict[str, int] = {}
for (node_id, partition) in starting_communities.items():
for node_id, partition in starting_communities.items():
node_id_as_str = identity(node_id)
native_safe[node_id_as_str] = partition
return native_safe
Expand Down Expand Up @@ -399,7 +399,6 @@ def _from_native(
native_cluster: gn.HierarchicalCluster,
identifier: _IdentityMapper,
) -> HierarchicalCluster:

if not isinstance(native_cluster, gn.HierarchicalCluster):
raise TypeError(
"This class method is only valid for graspologic_native.HierarchicalCluster"
Expand All @@ -420,7 +419,7 @@ def hierarchical_leiden(
List[Tuple[Any, Any, Union[int, float]]],
nx.Graph,
np.ndarray,
scipy.sparse.csr.csr_matrix,
scipy.sparse.csr_matrix,
],
max_cluster_size: int = 1000,
starting_communities: Optional[Dict[str, int]] = None,
Expand Down
2 changes: 1 addition & 1 deletion graspologic/pipeline/embed/adjacency_spectral_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def adjacency_spectral_embedding(

node_labels = np.array(list(graph.nodes()))

graph_as_csr = nx.to_scipy_sparse_matrix(
graph_as_csr = nx.to_scipy_sparse_array(
graph, weight=used_weight_attribute, nodelist=node_labels
)

Expand Down
2 changes: 1 addition & 1 deletion graspologic/pipeline/embed/laplacian_spectral_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def laplacian_spectral_embedding(

node_labels = np.array(list(graph.nodes()))

graph_as_csr = nx.to_scipy_sparse_matrix(
graph_as_csr = nx.to_scipy_sparse_array(
graph, weight=used_weight_attribute, nodelist=node_labels
)

Expand Down
2 changes: 1 addition & 1 deletion graspologic/pipeline/embed/omnibus_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def _augment_graph(
weight_attribute: Optional[str],
perform_augment_diagonal: bool = True,
) -> np.ndarray:
graph_sparse = nx.to_scipy_sparse_matrix(
graph_sparse = nx.to_scipy_sparse_array(
graph, weight=weight_attribute, nodelist=node_ids
)

Expand Down
1 change: 0 additions & 1 deletion graspologic/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,6 @@ def _distplot(
xlabel: str = "",
ylabel: str = "Density",
) -> matplotlib.pyplot.Axes:

plt.figure(figsize=figsize)
ax = plt.gca()
palette = sns.color_palette(palette)
Expand Down
1 change: 0 additions & 1 deletion graspologic/plot/plot_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,6 @@ def matrixplot( # type: ignore
# in the opposite order
rev_group = list(col_group[::-1])
for i, sc in enumerate(rev_group):

# Add a new axis when needed
tick_ax = divider.append_axes(
"top", size="1%", pad=col_tick_pad[i], sharex=ax
Expand Down
1 change: 0 additions & 1 deletion tests/embed/test_omni.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def generate_data(n, seed=1, symetric=True):


class TestOmni(unittest.TestCase):

# Below tests omni matrix generation code
def test_omni_matrix_ones_zeros(self):
# Should get all ones
Expand Down
1 change: 0 additions & 1 deletion tests/layouts/nooverlap/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class TestGrid(unittest.TestCase):

# def setUp(self):
# self.g = _GridBuckets(10)

Expand Down
1 change: 0 additions & 1 deletion tests/layouts/nooverlap/test_overlap_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def test_grid_is_overlap(self):
self.assertFalse(overlaps)

def test_overlap_check_list(self):

to_check = _Node(0, 2, 2, 1, -1, "blue")
others = [
_Node(1, 5, 5, 1, -1, "blue"),
Expand Down
9 changes: 4 additions & 5 deletions tests/partition/test_leiden.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def test_from_native(self):
# test from_native indirectly through calling graspologic.partition.hierarchical_leiden()

def test_final_hierarchical_clustering(self):

hierarchical_clusters = HierarchicalClusters(
[
HierarchicalCluster("1", 0, None, 0, False),
Expand Down Expand Up @@ -189,7 +188,7 @@ def test_correct_types(self):

cleared_partitions = good_args.copy()
del cleared_partitions["starting_communities"]
as_csr = nx.to_scipy_sparse_matrix(graph)
as_csr = nx.to_scipy_sparse_array(graph)
partitions = leiden(graph=as_csr, **cleared_partitions)
node_ids = partitions.keys()
for node_id in node_ids:
Expand Down Expand Up @@ -310,7 +309,7 @@ def test_isolate_nodes_in_ndarray_are_not_returned(self):
self.assert_isolate_not_in_hierarchical_result(hierarchical_partitions)

def test_isolate_nodes_in_csr_matrix_are_not_returned(self):
sparse_adj_matrix = nx.to_scipy_sparse_matrix(self.graph)
sparse_adj_matrix = nx.to_scipy_sparse_array(self.graph)

self.assertEqual(
10,
Expand Down Expand Up @@ -475,8 +474,8 @@ def test_matrices(self):
dense_undirected = nx.to_numpy_array(graph)
dense_directed = nx.to_numpy_array(di_graph)

sparse_undirected = nx.to_scipy_sparse_matrix(graph)
sparse_directed = nx.to_scipy_sparse_matrix(di_graph)
sparse_undirected = nx.to_scipy_sparse_array(graph)
sparse_directed = nx.to_scipy_sparse_array(di_graph)

expected = [("0", "1", 2.2), ("1", "2", 0.001)]
_, edges = _adjacency_matrix_to_edge_list(
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/embed/test_adjacency_spectral_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def test_unweighted_graph_warning(self):

def test_dimensions(self):
graph = self.graph.copy()
sparse = nx.to_scipy_sparse_matrix(graph)
sparse = nx.to_scipy_sparse_array(graph)
ranked = graspologic.utils.pass_to_ranks(sparse)
ase = AdjacencySpectralEmbed(n_components=100, n_elbows=None, svd_seed=1234)
core_response = ase.fit_transform(ranked)
Expand Down
2 changes: 1 addition & 1 deletion tests/pipeline/embed/test_laplacian_spectral_embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_unweighted_graph_warning(self):

def test_dimensions(self):
graph = self.graph.copy()
sparse = nx.to_scipy_sparse_matrix(graph)
sparse = nx.to_scipy_sparse_array(graph)
loopless = graspologic.utils.remove_loops(sparse)
ranked = graspologic.utils.pass_to_ranks(loopless)
lse = LaplacianSpectralEmbed(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_casc.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

np.random.seed(5)


# UTILITY FUNCTIONS
def gen_covariates(m1, m2, labels, type, ndim=3):
n = len(labels)
Expand Down Expand Up @@ -107,7 +108,6 @@ def test_labels_match(A, labels, M):


def test_wrong_inputs(A, X):

with pytest.raises(ValueError):
"wrong assortative type"
CASE(assortative="1")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ def setUpClass(cls):
cls.A = er_np(20, 0.5)
cls.B = csr_matrix(cls.A)
cls.C = nx.from_numpy_array(cls.A)
cls.D = nx.from_scipy_sparse_matrix(cls.B)
cls.D = nx.from_scipy_sparse_array(cls.B)

def test_numpy_edge_swap(self):
Swapper = EdgeSwapper(self.A)
Expand Down
22 changes: 11 additions & 11 deletions tests/test_spectral_nomination.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
n_verts = 50
p = np.array([[0.7, 0.25, 0.2], [0.25, 0.8, 0.3], [0.2, 0.3, 0.85]])
labels = np.array([0] * n_verts + [1] * n_verts + [2] * n_verts)
adj = np.array(sbm(3 * [n_verts], p), dtype=np.int)
adj = np.array(sbm(3 * [n_verts], p), dtype=int)
embeder = AdjacencySpectralEmbed()
pre_embeded = embeder.fit_transform(adj)

Expand All @@ -32,34 +32,34 @@ def _nominate(self, X, seed, nominator=None, k=None):

def test_seed_inputs(self):
with self.assertRaises(IndexError):
self._nominate(adj, np.zeros((1, 50), dtype=np.int))
self._nominate(adj, np.zeros((1, 50), dtype=int))
with self.assertRaises(TypeError):
self._nominate(adj, np.random.random((10, 2)))

def test_X_inputs(self):
with self.assertRaises(IndexError):
self._nominate(np.zeros((5, 5, 5), dtype=np.int), np.zeros(3, dtype=np.int))
self._nominate(np.zeros((5, 5, 5), dtype=int), np.zeros(3, dtype=int))
with self.assertRaises(TypeError):
self._nominate([[0] * 10] * 10, np.zeros(3, dtype=np.int))
self._nominate([[0] * 10] * 10, np.zeros(3, dtype=int))
# embedding should have fewer cols than rows.
svn = SpectralVertexNomination(input_graph=False)
with self.assertRaises(IndexError):
self._nominate(
np.zeros((10, 20), dtype=np.int),
np.zeros(3, dtype=np.int),
np.zeros((10, 20), dtype=int),
np.zeros(3, dtype=int),
nominator=svn,
)
# adj matrix should be square
with self.assertRaises(IndexError):
self._nominate(np.zeros((3, 4), dtype=np.int), np.zeros(3, dtype=np.int))
self._nominate(np.zeros((3, 4), dtype=int), np.zeros(3, dtype=int))

def _test_k(self):
# k should be > 0
with self.assertRaises(ValueError):
self._nominate(adj, np.zeros(3, dtype=np.int), k=0)
self._nominate(adj, np.zeros(3, dtype=int), k=0)
# k of wrong type
with self.assertRaises(TypeError):
self._nominate(adj, np.zeros(3, dtype=np.int), k="hello world")
self._nominate(adj, np.zeros(3, dtype=int), k="hello world")

def test_constructor_inputs(self):
with self.assertRaises(ValueError):
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_basic_unattributed(self):
seeds = [
np.array([8]),
np.array([2, 6, 9, 15, 25]),
np.arange(n_verts - 1, dtype=np.int),
np.arange(n_verts - 1, dtype=int),
]
for nominator, seed in itertools.product(nominators, seeds):
self._nominate(adj, seed, nominator)
Expand All @@ -99,7 +99,7 @@ def test_pre_embedded(self):
seeds = [
np.array([8]),
np.array([2, 6, 9, 15, 25]),
np.arange(n_verts - 1, dtype=np.int),
np.arange(n_verts - 1, dtype=int),
]
for seed in seeds:
svn = SpectralVertexNomination(input_graph=False)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_svd.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_outputs(self):
]
)
P = X @ X.T
A = np.random.binomial(1, P).astype(np.float)
A = np.random.binomial(1, P).astype(float)

n_components = 3

Expand Down Expand Up @@ -75,7 +75,7 @@ def test_eigsh(self):
]
)
P = X @ X.T
A = np.random.binomial(1, P).astype(np.float)
A = np.random.binomial(1, P).astype(float)
A = symmetrize(A, method="triu")
n_components = 3

Expand Down

0 comments on commit 7e346cf

Please sign in to comment.