<commit_before>from unittest import TestCase

import pandas as pd
import pandas.util.testing as tm
import numpy as np

import trtools.core.topper as topper
reload(topper)

arr = np.random.randn(10000)
s = pd.Series(arr)
df = tm.makeDataFrame()

class TestTopper(TestCase):

    def __init__(self, *args, **kwargs):
        TestCase.__init__(self, *args, **kwargs)

    def runTest(self):
        pass

    def setUp(self):
        pass

    def test_topn_largest(self):
        # get the n largest
        bn_res = topper.bn_topn(arr, 10)
        assert bn_res[0] == max(arr) # sanity check
        pd_res = s.order(ascending=False)[:10]
        tm.assert_almost_equal(bn_res, pd_res)

        # change result to biggest to smallest
        bn_res = topper.bn_topn(arr, 10, ascending=False)
        assert bn_res[0] == max(arr) # sanity check
        pd_res = s.order(ascending=False)[:10] # grab from end since we reversed
        tm.assert_almost_equal(bn_res, pd_res)


    def test_top_smallest(self):
        # get the nsmallest
        bn_res = topper.bn_topn(arr, -10)
        assert bn_res[0] == min(arr) # sanity check
        pd_res = s.order()[:10]
        tm.assert_almost_equal(bn_res, pd_res)

        # change result to biggest to smallest
        bn_res = topper.bn_topn(arr, 10, ascending=False)
        bn_res = topper.bn_topn(arr, -10, ascending=False)
        assert bn_res[-1] == min(arr) # sanity check
        pd_res = s.order(ascending=False)[-10:] # grab from end since we reversed
        tm.assert_almost_equal(bn_res, pd_res)

    def test_top_arg(self):
        # get the nlargest
        bn_res = topper.bn_topn(arr, 10)
        bn_args = topper.bn_topargn(arr, 10)
        arg_res = arr[bn_args]
        tm.assert_almost_equal(bn_res, arg_res)

        # get the nsmallest
        bn_res = topper.bn_topn(arr, -10)
        bn_args = topper.bn_topargn(arr, -10)
        arg_res = arr[bn_args]
        tm.assert_almost_equal(bn_res, arg_res)

        # get the nsmallest
        bn_res = topper.bn_topn(arr, -10, ascending=False)
        bn_args = topper.bn_topargn(arr, -10, ascending=False)
        arg_res = arr[bn_args]
        tm.assert_almost_equal(bn_res, arg_res)
<commit_msg>added failing test<commit_after>from unittest import TestCase

import pandas as pd
import pandas.util.testing as tm
import numpy as np

import trtools.core.topper as topper
reload(topper)

arr = np.random.randn(10000)
s = pd.Series(arr)
df = tm.makeDataFrame()

class TestTopper(TestCase):

    def __init__(self, *args, **kwargs):
        TestCase.__init__(self, *args, **kwargs)

    def runTest(self):
        pass

    def setUp(self):
        pass

    def test_topn_largest(self):
        # get the n largest
        bn_res = topper.bn_topn(arr, 10)
        assert bn_res[0] == max(arr) # sanity check
        pd_res = s.order(ascending=False)[:10]
        tm.assert_almost_equal(bn_res, pd_res)

        # change result to biggest to smallest
        bn_res = topper.bn_topn(arr, 10, ascending=True)
        assert bn_res[-1] == max(arr) # sanity check
        pd_res = s.order(ascending=True)[-10:] # grab from end since we reversed
        tm.assert_almost_equal(bn_res, pd_res)

    def test_topn_big_N(self):
        """
        When calling topn where N is greater than the number of non-nan values. 

        This can happen if you're tracking a Frame of returns where not all series start at the same time. 

        It's possible that in the begining or end, or anytime for that matter, you might not have enough
        values. This screws up the logic.
        """
        # test data
        arr = np.random.randn(100)
        arr[5:] = np.nan # only first four are non-na
        s = pd.Series(arr)

        # top
        bn_res = topper.bn_topn(arr, 10)
        assert bn_res[0] == max(arr) # sanity check
        pd_res = s.order(ascending=False)[:10].dropna()
        tm.assert_almost_equal(bn_res, pd_res)

        # bottom
        bn_res = topper.bn_topn(arr, -10)
        assert bn_res[0] == min(arr) # sanity check
        pd_res = s.order()[:10].dropna() # grab from end since we reversed
        tm.assert_almost_equal(bn_res, pd_res)

    def test_top_smallest(self):
        # get the nsmallest
        bn_res = topper.bn_topn(arr, -10)
        assert bn_res[0] == min(arr) # sanity check
        pd_res = s.order()[:10]
        tm.assert_almost_equal(bn_res, pd_res)

        # change ordering
        bn_res = topper.bn_topn(arr, -10, ascending=False)
        assert bn_res[-1] == min(arr) # sanity check
        pd_res = s.order(ascending=False)[-10:] # grab from end since we reversed
        tm.assert_almost_equal(bn_res, pd_res)

    def test_top_arg(self):
        # get the nlargest
        bn_res = topper.bn_topn(arr, 10)
        bn_args = topper.bn_topargn(arr, 10)
        arg_res = arr[bn_args]
        tm.assert_almost_equal(bn_res, arg_res)

        # get the nsmallest
        bn_res = topper.bn_topn(arr, -10)
        bn_args = topper.bn_topargn(arr, -10)
        arg_res = arr[bn_args]
        tm.assert_almost_equal(bn_res, arg_res)

        # get the nsmallest
        bn_res = topper.bn_topn(arr, -10, ascending=False)
        bn_args = topper.bn_topargn(arr, -10, ascending=False)
        arg_res = arr[bn_args]
        tm.assert_almost_equal(bn_res, arg_res)

{'fraction_non_alphanumeric': 0.1042057829515584, 'fraction_numerical': 0.016898235073225687, 'mean_word_length': 2.548967355096602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7300117', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1837, 'n_words': 445}