4

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
drhagen
  • 8,331
  • 8
  • 53
  • 82

2 Answers2

5

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
drhagen
  • 8,331
  • 8
  • 53
  • 82
3

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.

jvz
  • 1,183
  • 6
  • 13