22
33import pytest
44
5- from squidpy .gr import spatial_autocorr
65from squidpy ._constants ._constants import SpatialAutocorr
6+ from squidpy .gr import spatial_autocorr
7+
78
89def test_spagft_incompatible_shapes ():
9- from squidpy .gr ._spagft import _spagft
1010 import numpy as np
1111 from scipy .sparse import lil_matrix
12+
13+ from squidpy .gr ._spagft import _spagft
14+
1215 n = 10
1316 g = lil_matrix ((n , n ))
1417 for i in range (n ):
1518 g [i , (i + 1 ) % n ] = 1
1619 g [i , (i - 1 ) % n ] = 1
1720 g = g .tocsr ()
1821 vals = np .random .rand (5 , 7 )
19- with pytest .raises (( ValueError ) ):
22+ with pytest .raises (ValueError ):
2023 _spagft (g , vals )
2124
25+
2226def test_spagft_svg_identification ():
2327 import numpy as np
2428 from anndata import AnnData
29+
2530 from squidpy .gr import spatial_autocorr
2631
2732 n_cells = 50
@@ -31,6 +36,7 @@ def test_spagft_svg_identification():
3136 X = np .vstack ([spatial_pattern , random_gene ])
3237 adata = AnnData (X = X .T )
3338 from scipy .sparse import lil_matrix
39+
3440 g = lil_matrix ((n_cells , n_cells ))
3541 for i in range (n_cells ):
3642 g [i , (i + 1 ) % n_cells ] = 1
@@ -40,22 +46,25 @@ def test_spagft_svg_identification():
4046 assert "GFT" in df .columns
4147 assert df ["GFT" ].iloc [0 ] > df ["GFT" ].iloc [1 ]
4248
49+
4350def test_spagft_enum_recognition ():
4451 # Check that the enum contains "spagft"
4552 assert hasattr (SpatialAutocorr , "SPAGFT" )
4653 # Check that spatial_autocorr accepts the enum member
4754 import numpy as np
4855 from anndata import AnnData
56+
4957 n_cells = 10
5058 np .random .seed (0 )
5159 X = np .random .normal (size = (n_cells , 2 ))
5260 adata = AnnData (X = X )
5361 from scipy .sparse import lil_matrix
62+
5463 g = lil_matrix ((n_cells , n_cells ))
5564 for i in range (n_cells ):
5665 g [i , (i + 1 ) % n_cells ] = 1
5766 g [i , (i - 1 ) % n_cells ] = 1
5867 adata .obsp ["spatial_connectivities" ] = g .tocsr ()
5968 # Should not raise
6069 df = spatial_autocorr (adata , mode = SpatialAutocorr .SPAGFT , copy = True )
61- assert "GFT" in df .columns
70+ assert "GFT" in df .columns
0 commit comments