From b05c7519d14f0c50b87676906e7f3db8798e23f6 Mon Sep 17 00:00:00 2001 From: jkanche Date: Wed, 25 Oct 2023 20:29:57 -0700 Subject: [PATCH] add some tests --- src/biocframe/BiocFrame.py | 2 +- tests/test_combine.py | 2 +- tests/test_initialize.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/biocframe/BiocFrame.py b/src/biocframe/BiocFrame.py index 12cf7a4..61a0db4 100644 --- a/src/biocframe/BiocFrame.py +++ b/src/biocframe/BiocFrame.py @@ -747,7 +747,7 @@ def __delitem__(self, name: str): self._column_names.remove(name) if self._mcols is not None: - self._mcols = self._mcols[:, _indices] + self._mcols = self._mcols[_indices, :] def __len__(self) -> int: """Number of rows. diff --git a/tests/test_combine.py b/tests/test_combine.py index 2563a19..b746a48 100644 --- a/tests/test_combine.py +++ b/tests/test_combine.py @@ -114,4 +114,4 @@ def test_combine_with_extras(): merged = combine(obj1, obj2) assert merged.metadata == obj1.metadata - assert merged.mcols.shape == obj1.mcols.shape + assert merged.mcols.shape == obj1.mcols.shape \ No newline at end of file diff --git a/tests/test_initialize.py b/tests/test_initialize.py index e81c352..bb4bcc2 100644 --- a/tests/test_initialize.py +++ b/tests/test_initialize.py @@ -135,3 +135,31 @@ def test_extra_bits(): bframe.metadata = {"FOO": "A"} assert bframe.metadata["FOO"] == "A" + + +def test_with_add_deletions(): + obj1 = BiocFrame( + { + "column1": [1, 2, 3], + "column2": [4, 5, 6], + }, + mcols=BiocFrame({"foo": [-1, -2], "bar": ["A", "B"]}), + metadata={"YAY": 2}, + ) + + assert isinstance(obj1.mcols, BiocFrame) + + obj1["new_column"] = [10, 11, "12"] + assert obj1.shape == (3, 3) + assert len(obj1.mcols) == 3 + + # welp assume i made a mistake earlier + obj1["new_column"] = [10, 11, 12] + assert obj1.shape == (3, 3) + assert len(obj1.mcols) == 3 + + # lets delete + del obj1["new_column"] + assert obj1.shape == (3, 2) + print(obj1.mcols) + assert len(obj1.mcols) == 2