Repository: stellargraph/stellargraph (language: python)

Issue:
Flaky test: test_normalize_adj in tests.core.test_utils
### Describe the bug

This test sometimes fails in a flaky manner:

- `tests.core.test_utils` `test_normalize_adj` (total = 5, in failed builds = 3, in successful builds = 2)
  - https://buildkite.com/stellar/stellargraph-public/builds/3837
  - https://buildkite.com/stellar/stellargraph-public/builds/3967
  - https://buildkite.com/stellar/stellargraph-public/builds/4148
  - https://buildkite.com/stellar/stellargraph-public/builds/4237 (2 times)



```
E       assert 5 == 4.0 ± 4.0e-01
E        +  where 4.0 ± 4.0e-01 = (4.0, 0.1)
E        +    where  = pytest.approx
E        +    and   4.0 = ()
E        +      where  = matrix([[0.22222222, 0.44444444, 0.33333333, 0.        , 0.        ,\n         0.        ],\n        [0.5       , 0.125 ...    ,\n         0.        ],\n        [0.        , 0.        , 0.        , 0.        , 0.        ,\n         0.        ]]).sum

tests/core/test_utils.py:44: AssertionError
```

Commit of most recent failure: https://github.com/stellargraph/stellargraph/commit/ee3bd69435ba0a7b630dd0ae566f095c99167e66

This has failed since other fixes for this test: #996 (#997).


Discussion / hints:

Fix patch:
diff --git a/stellargraph/data/epgm.py b/stellargraph/data/epgm.py
index cbad3a617..ec37391c8 100644
--- a/stellargraph/data/epgm.py
+++ b/stellargraph/data/epgm.py
@@ -21,7 +21,6 @@
 import json
 import uuid
 import numpy as np
-import chardet
 import scipy.sparse as sp
 
 import multiprocessing


Test patch:
diff --git a/tests/core/test_utils.py b/tests/core/test_utils.py
index 49fa2edd6..136dd057f 100644
--- a/tests/core/test_utils.py
+++ b/tests/core/test_utils.py
@@ -184,19 +184,20 @@ def test_smart_array_concatenate_broadcast():
         _check_smart_concatenate([a0, c43])
 
 
-@flaky_xfail_mark(AssertionError, 1678)
 def test_normalize_adj(example_graph):
     node_list = list(example_graph.nodes())
     Aadj = example_graph.to_adjacency_matrix()
     csr = normalize_adj(Aadj, symmetric=True)
     dense = csr.todense()
     eigen_vals, _ = np.linalg.eig(dense)
-    assert eigen_vals.max() == pytest.approx(1, abs=1e-7)
+    assert eigen_vals.max() == pytest.approx(1, abs=1e-5)
     assert csr.get_shape() == Aadj.get_shape()
 
+    # Sum of normalized adjacency matrix is equal to the number of positive degree nodes
     csr = normalize_adj(Aadj, symmetric=False)
     dense = csr.todense()
-    assert 5 == pytest.approx(dense.sum(), 0.1)
+    num_pos_degree_nodes = (Aadj.sum(axis=1) > 0).sum()
+    assert num_pos_degree_nodes == pytest.approx(dense.sum(), 0.1)
     assert csr.get_shape() == Aadj.get_shape()
 
 
@@ -212,7 +213,7 @@ def test_normalized_laplacian(example_graph):
     assert laplacian.shape == Aadj.get_shape()
 
     # Sum of laplacian is equal to the number of degree 0 nodes
-    laplacian = normalized_laplacian(Aadj, symmetric=False) 
+    laplacian = normalized_laplacian(Aadj, symmetric=False)
     num_degree_zero_nodes = (Aadj.sum(axis=1) == 0).sum()
     assert num_degree_zero_nodes == pytest.approx(laplacian.sum(), abs=1e-7)
     assert laplacian.get_shape() == Aadj.get_shape()