def test_too_big_n_df(self): df = pd.DataFrame(np.random.randn(100, 10)) df[df > 0] = np.nan testdf = topper.topn_df(df, 10) for x in range(len(df)): correct = df.iloc[x].order(ascending=False).reset_index(drop=True) test = testdf.iloc[x] tm.assert_almost_equal(test, correct) testdf = topper.topn_df(df, 2) for x in range(len(df)): correct = df.iloc[x].order(ascending=False).reset_index( drop=True)[:2] test = testdf.iloc[x] tm.assert_almost_equal(test, correct) # bottom testdf = topper.topn_df(df, -2) for x in range(len(df)): correct = df.iloc[x].order().reset_index(drop=True)[:2] test = testdf.iloc[x] tm.assert_almost_equal(test, correct) # bottom testdf = topper.topn_df(df, -20) for x in range(len(df)): correct = df.iloc[x].order().reset_index(drop=True)[:20] test = testdf.iloc[x] tm.assert_almost_equal(test, correct)
def test_too_big_n_df(self): df = pd.DataFrame(np.random.randn(100, 10)) df[df > 0] = np.nan testdf = topper.topn_df(df, 10) for x in range(len(df)): correct = df.iloc[x].order(ascending=False).reset_index(drop=True) test = testdf.iloc[x] tm.assert_almost_equal(test, correct) testdf = topper.topn_df(df, 2) for x in range(len(df)): correct = df.iloc[x].order(ascending=False).reset_index(drop=True)[:2] test = testdf.iloc[x] tm.assert_almost_equal(test, correct) # bottom testdf = topper.topn_df(df, -2) for x in range(len(df)): correct = df.iloc[x].order().reset_index(drop=True)[:2] test = testdf.iloc[x] tm.assert_almost_equal(test, correct) # bottom testdf = topper.topn_df(df, -20) for x in range(len(df)): correct = df.iloc[x].order().reset_index(drop=True)[:20] test = testdf.iloc[x] tm.assert_almost_equal(test, correct)
def test_df_topn(self): # long way of getting the topn tops = df.apply(lambda s: s.topn(2, ascending=False), axis=1) correct = pd.DataFrame(tops, index=df.index) test = topper.topn_df(df, 2, ascending=False) tm.assert_frame_equal(test, correct) # sanity check, make sure first value is right c = df.iloc[0].order()[-1] t = test.iloc[0][0] tm.assert_almost_equal(t, c) # bottom 2 tops = df.apply(lambda s: s.topn(-2), axis=1) correct = pd.DataFrame(tops, index=df.index) test = topper.topn_df(df, -2) tm.assert_frame_equal(test, correct) # sanity check, make sure first value is right c = df.iloc[0].order()[0] t = test.iloc[0][0] tm.assert_almost_equal(t, c)
def test_df_topn(self): # long way of getting the topn tops = df.apply(lambda s: s.topn(2, ascending=False), axis=1) correct = pd.DataFrame(tops, index=df.index) test = topper.topn_df(df, 2, ascending=False) tm.assert_almost_equal(test, correct) # sanity check, make sure first value is right c = df.iloc[0].order()[-1] t = test.iloc[0][0] tm.assert_almost_equal(t, c) # bottom 2 tops = df.apply(lambda s: s.topn(-2), axis=1) correct = pd.DataFrame(tops, index=df.index) test = topper.topn_df(df, -2) tm.assert_almost_equal(test, correct) # sanity check, make sure first value is right c = df.iloc[0].order()[0] t = test.iloc[0][0] tm.assert_almost_equal(t, c)