Exemple #1
0
    def test_nans(self):
        """
        bottleneck.partsort doesn't handle nans. We need to correct for them.

        the arg version is trickiers since we need to make sure to
        translate back into the nan-filled array
        """
        nanarr = np.arange(10).astype(float)
        nanarr[nanarr % 2 == 0] = np.nan

        test = topper.topn(nanarr, 3)
        correct = [9, 7, 5]
        tm.assert_almost_equal(test, correct)

        test = topper.topn(nanarr, -3)
        correct = [1, 3, 5]
        tm.assert_almost_equal(test, correct)

        test = topper.topargn(nanarr, 3)
        correct = [9, 7, 5]
        tm.assert_almost_equal(test, correct)

        test = topper.topargn(nanarr, -3)
        correct = [1, 3, 5]
        tm.assert_almost_equal(test, correct)

        test = topper.topargn(nanarr, -3, ascending=False)
        correct = [5, 3, 1]
        tm.assert_almost_equal(test, correct)
Exemple #2
0
    def test_nans(self):
        """
        bottleneck.partsort doesn't handle nans. We need to correct for them.

        the arg version is trickiers since we need to make sure to 
        translate back into the nan-filled array
        """
        nanarr = np.arange(10).astype(float)
        nanarr[nanarr % 2 == 0] = np.nan

        test = topper.topn(nanarr, 3)
        correct = [9,7,5]
        tm.assert_almost_equal(test, correct)

        test = topper.topn(nanarr, -3)
        correct = [1,3,5]
        tm.assert_almost_equal(test, correct)

        test = topper.topargn(nanarr, 3)
        correct = [9,7,5]
        tm.assert_almost_equal(test, correct)

        test = topper.topargn(nanarr, -3)
        correct = [1,3,5]
        tm.assert_almost_equal(test, correct)

        test = topper.topargn(nanarr, -3, ascending=False)
        correct = [5,3,1]
        tm.assert_almost_equal(test, correct)
Exemple #3
0
    def test_test_ndim(self):
        """
        Make sure topn and topargn doesn't accept DataFrame
        """
        try:
            topper.topn(df, 1)
        except:
            pass
        else:
            assert False

        try:
            topper.topargn(df, 1)
        except:
            pass
        else:
            assert False
Exemple #4
0
    def test_test_ndim(self):
        """
        Make sure topn and topargn doesn't accept DataFrame
        """
        try:
            topper.topn(df, 1)
        except:
            pass
        else:
            assert False

        try:
            topper.topargn(df, 1)
        except:
            pass
        else:
            assert False