Skip to content

Commit

Permalink
Fix bug with modifiying polars object (#31)
Browse files Browse the repository at this point in the history
* Learning how to modify polars dataframes; this is why i should learn polars fully :) 
* Add tests
  • Loading branch information
jkanche authored Jun 11, 2024
1 parent cf96757 commit 36f639e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/iranges/IRanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,7 @@ def to_polars(self) -> "polars.DataFrame":
output = pl.concat([output, self._mcols.to_polars()])

if self._names is not None:
output["rownames"] = self._names
output = output.with_columns(names=self._names)

return output

Expand Down
15 changes: 13 additions & 2 deletions tests/test_IRanges_polars.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
__license__ = "MIT"


def test_pandas():
def test_from_polars():
df = pl.DataFrame({"start": [1, 2, 3, 4], "width": [4, 5, 6, 7]})

x = IRanges.from_polars(df)
Expand All @@ -17,10 +17,21 @@ def test_pandas():
assert isinstance(x.mcols, BiocFrame)


def test_pandas_export():
def test_to_polars_export():
x = IRanges([1, 2, 3, 4], [4, 5, 6, 7])

y = x.to_polars()
assert y is not None
assert isinstance(y, pl.DataFrame)
assert set(y.columns).issubset(["starts", "ends", "widths"])


def test_to_polars_names():
x = IRanges(
[1, 2, 3, 4], [4, 5, 6, 7], names=["range1", "range2", "range3", "range4"]
)

y = x.to_polars()
assert y is not None
assert isinstance(y, pl.DataFrame)
assert set(y.columns).issubset(["starts", "ends", "widths", "names"])

0 comments on commit 36f639e

Please sign in to comment.