mardi 19 septembre 2017

pandas assert_frame_equal behavior

I am attempting to compare two DataFrames with pandas testing assert_frame_equal. These frames contain floats that I want to compare to some user defined precision.

The check_less_precise argument from assert_frame_equal seems to suggest that I can specify the number of digits after the decimal point to compare. To quote the main page -

check_less_precise: Specify comparison precision. Only used when check_exact is False. 5 digits (False) or 3 digits (True) after decimal points are compared. If int, then specify the digits to compare

API Reference

However, This doesn't seem to work when the floats are less than 1.

This raises an AssertionError

import pandas as pd

expected = pd.DataFrame([{"col": 0.1}])
output = pd.DataFrame([{"col": 0.12}])
pd.testing.assert_frame_equal(expected, output, check_less_precise=1)

while this does not

expected = pd.DataFrame([{"col": 1.1}])
output = pd.DataFrame([{"col": 1.12}])
pd.testing.assert_frame_equal(expected, output, check_less_precise=1)

can someone help explain this behavior, is this a bug?

Aucun commentaire:

Enregistrer un commentaire