ELVIS-Project / vis-framework

Thoroughly modern symbolic musical data analysis suite.
http://elvisproject.ca/
31 stars 6 forks source link

Make an assertDataFramesEqual() Method #329

Closed crantila closed 8 years ago

crantila commented 9 years ago

So many of our tests compare two DataFrame objects for equality, and it's a little different and a little error-prone every time. I should subclass unittest.TestCase, add assertDataFramesEqual(), then have all the VIS tests subclass that.

alexandermorgan commented 9 years ago

Great idea but why reinvent the wheel? Pandas has an undocumented testing suite. Try this:

import pandas as pd from pandas.util.testing import assert_frame_equal

ser1 = pd.Series([2, float('NaN'), 7.18]) ser2 = pd.Series([-18, 7, 'finally'])

df1 = pd.concat([ser1, ser2], axis=1) y = assert_frame_equal(df1, df1)

crantila commented 9 years ago

I'm glad you pointed out this issue again. I learned recently that the best solution to this kind of situation is using the unittest module's addTypeEqualityFunc() method to add a type-specific equality-checking method to a TestCase instance. This then allows you to use assertEqual() just as for built-in types.

I suppose we could use addTypeEqualityFunc() to add the existing Pandas function, but relying on undocumented functionality makes me uneasy. What do you think, @mrbannon?

alexandermorgan commented 9 years ago

It may be undocumented but it's what the pandas people use for their own tests so I wouldn't worry about it.

alexandermorgan commented 8 years ago

Now the equals() method is sort of documented: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.equals.html

df1.equals(df2) Returns a boolean if the values are equal. NaNs are considered equal.