Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two polars DataFrames for equality

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
like image 409
drhagen Avatar asked Feb 18 '26 04:02

drhagen


2 Answers

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.

like image 61
jvz Avatar answered Feb 20 '26 16:02

jvz


As of polars 0.19.16, frame_equals was deprecated in favour of pl.DataFrame.equals.

import polars as pl

pl.DataFrame({"x": [1,2,3]}).equals(pl.DataFrame({"x": [1,2,3]})) # True
like image 33
Hericks Avatar answered Feb 20 '26 18:02

Hericks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!