forked from pola-rs/polars
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(python): Handle
DataFrame.vstack
stacking itself (pola-rs#9895)
- Loading branch information
Showing
6 changed files
with
77 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
|
||
import polars as pl | ||
from polars.testing import assert_frame_equal | ||
|
||
|
||
@pytest.fixture() | ||
def df1() -> pl.DataFrame: | ||
return pl.DataFrame({"foo": [1, 2], "bar": [6, 7], "ham": ["a", "b"]}) | ||
|
||
|
||
@pytest.fixture() | ||
def df2() -> pl.DataFrame: | ||
return pl.DataFrame({"foo": [3, 4], "bar": [8, 9], "ham": ["c", "d"]}) | ||
|
||
|
||
def test_vstack(df1: pl.DataFrame, df2: pl.DataFrame) -> None: | ||
result = df1.vstack(df2) | ||
expected = pl.DataFrame( | ||
{"foo": [1, 2, 3, 4], "bar": [6, 7, 8, 9], "ham": ["a", "b", "c", "d"]} | ||
) | ||
assert_frame_equal(result, expected) | ||
|
||
|
||
def test_vstack_in_place(df1: pl.DataFrame, df2: pl.DataFrame) -> None: | ||
df1.vstack(df2, in_place=True) | ||
expected = pl.DataFrame( | ||
{"foo": [1, 2, 3, 4], "bar": [6, 7, 8, 9], "ham": ["a", "b", "c", "d"]} | ||
) | ||
assert_frame_equal(df1, expected) | ||
|
||
|
||
def test_vstack_self(df1: pl.DataFrame) -> None: | ||
result = df1.vstack(df1) | ||
expected = pl.DataFrame( | ||
{"foo": [1, 2, 1, 2], "bar": [6, 7, 6, 7], "ham": ["a", "b", "a", "b"]} | ||
) | ||
assert_frame_equal(result, expected) | ||
|
||
|
||
def test_vstack_self_in_place(df1: pl.DataFrame) -> None: | ||
df1.vstack(df1, in_place=True) | ||
expected = pl.DataFrame( | ||
{"foo": [1, 2, 1, 2], "bar": [6, 7, 6, 7], "ham": ["a", "b", "a", "b"]} | ||
) | ||
assert_frame_equal(df1, expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters