Skip to content

Commit

Permalink
making copy of lists inside functions likely to have side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
anushka255 committed Aug 13, 2024
1 parent d131aeb commit c03bb6a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
12 changes: 8 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
anndata>=0.7.6
scanpy>=1.7.2
POT==0.9.0
numpy
scipy
numpy~=1.24.4
scipy~=1.10.1
scikit-learn>=0.24.0
IPython>=7.18.1
pytest

pytest~=8.3.2
seaborn~=0.13.2
matplotlib~=3.7.5
pandas~=2.0.3
statsmodels~=0.14.1
networkx~=3.1
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import scanpy as sc
import pytest
from paste.helper import intersect
from pandas.testing import assert_frame_equal


test_dir = Path(__file__).parent
input_dir = test_dir / "data/input"
Expand All @@ -29,6 +27,9 @@ def slices():

@pytest.fixture(scope="session")
def intersecting_slices(slices):
# Make a copy of the list
slices = list(slices)

common_genes = slices[0].var.index
for slice in slices[1:]:
common_genes = intersect(common_genes, slice.var.index)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def test_pairwise_alignment(slices):
def test_center_alignment(slices):
temp_dir = Path(tempfile.mkdtemp())

# Make a copy of the list
slices = list(slices)
n_slices = len(slices)
center_slice, pairwise_info = center_align(
slices[0],
Expand Down Expand Up @@ -255,4 +257,4 @@ def test_gromov_linesearch(slices):
)
assert alpha == 1.0
assert fc == 1
assert round(cost_G, 6) == -11.419226
assert round(cost_G, 6) == -11.205454
4 changes: 1 addition & 3 deletions tests/test_paste_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@

def test_intersect(slices):
common_genes = intersect(slices[1].var.index, slices[2].var.index)

assert np.all(
np.equal(
common_genes, np.genfromtxt(output_dir / "common_genes.csv", dtype=str)
)
)


def test_kl_divergence_bakcend(slices):
def test_kl_divergence_backend(slices):
nx = ot.backend.NumpyBackend()

common_genes = intersect(slices[1].var.index, slices[2].var.index)
Expand All @@ -43,4 +42,3 @@ def test_kl_divergence_bakcend(slices):
rtol=1e-05,
atol=1e-08,
)

0 comments on commit c03bb6a

Please sign in to comment.