Skip to content

Commit

Permalink
Correctly handle mcols in get/setitem calls. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Oct 31, 2023
1 parent a21937c commit 0c92797
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/iranges/IRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def __getitem__(
start=self._start[idx],
width=self._width[idx],
names=ut.subset(self._names, idx) if self._names is not None else None,
mcols=self._mcols[list(idx), :], # doesn't support ranges yet.
mcols=self._mcols[idx, :],
metadata=self._metadata,
)

Expand All @@ -337,7 +337,7 @@ def __setitem__(
idx, scalar = ut.normalize_subscript(args, len(self), self._names)
self._start[idx] = value._start
self._width[idx] = value._width
# self._mcols[list(idx),:] = value._mcols # doesn't support ranges yet.
self._mcols[idx, :] = value._mcols

if value._names is not None:
if self._names is None:
Expand Down
8 changes: 4 additions & 4 deletions tests/test_IRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ def test_IRanges_setitem():
assert (x.get_width() == np.array([4, 60, 70, 7])).all()
assert x.get_names() is None

# x = IRanges(starts, widths, mcols = BiocFrame({"foo": ['a', 'b', 'c', 'd']}))
# y = IRanges(starts2, widths2, mcols = BiocFrame({"foo": ['A', 'B', 'C', 'D']}))
# x[1:3] = y[1:3]
# assert x.get_mcols().column("foo") == ['a', 'B', 'C', 'd']
x = IRanges(starts, widths, mcols=BiocFrame({"foo": ["a", "b", "c", "d"]}))
y = IRanges(starts2, widths2, mcols=BiocFrame({"foo": ["A", "B", "C", "D"]}))
x[1:3] = y[1:3]
assert x.get_mcols().column("foo") == ["a", "B", "C", "d"]

x = IRanges(starts, widths, names=["a", "b", "c", "d"])
y = IRanges(starts2, widths2, names=["A", "B", "C", "D"])
Expand Down

0 comments on commit 0c92797

Please sign in to comment.