Skip to content

Commit

Permalink
test(python): Use assert_frame_equal instead of `assert df.frame_eq…
Browse files Browse the repository at this point in the history
…ual(...)` (pola-rs#6553)
  • Loading branch information
stinodego authored and vincent committed Jan 30, 2023
1 parent 8bbb113 commit 835b0fb
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions py-polars/tests/unit/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -2886,3 +2886,49 @@ def test_reverse() -> None:
"b": [None, None, None],
"c": ["abc", "def", None]
}


def test_frame_equal() -> None:
# Values are checked
df1 = pl.DataFrame(
{
"foo": [1, 2, 3],
"bar": [6.0, 7.0, 8.0],
"ham": ["a", "b", "c"],
}
)
df2 = pl.DataFrame(
{
"foo": [3, 2, 1],
"bar": [8.0, 7.0, 6.0],
"ham": ["c", "b", "a"],
}
)

assert df1.frame_equal(df1)
assert not df1.frame_equal(df2)

# Column names are checked
df3 = pl.DataFrame(
{
"a": [1, 2, 3],
"b": [6.0, 7.0, 8.0],
"c": ["a", "b", "c"],
}
)
assert not df1.frame_equal(df3)

# Datatypes are NOT checked
df = pl.DataFrame(
{
"foo": [1, 2, None],
"bar": [6.0, 7.0, None],
"ham": ["a", "b", None],
}
)
assert df.frame_equal(df.with_columns(pl.col("foo").cast(pl.Int8)))
assert df.frame_equal(df.with_columns(pl.col("ham").cast(pl.Categorical)))

# The null_equal parameter determines if None values are considered equal
assert df.frame_equal(df)
assert not df.frame_equal(df, null_equal=False)

0 comments on commit 835b0fb

Please sign in to comment.