Compare two polars DataFrames for equality

Viewed 270

How do I compare two polars DataFrames for value equality? It appears that == is only true if the two tables are the same object:

import polars as pl
pl.DataFrame({"x": [1,2,3]}) == pl.DataFrame({"x": [1,2,3]})  # False
2 Answers

It's the frame_equal method of DataFrame:

import polars as pl
pl.DataFrame({"x": [1,2,3]}).frame_equal(pl.DataFrame({"x": [1,2,3]}))  # True

In addition to the correct answer above, it is good to note that for unit testing there is polars.testing.assert_frame_equal, which provides better error reporting, has more configuration options and raises an assertion on False.

Related