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


class algorithm(object):
    goal_time = 0.2

    def setup(self):
        N = 100000

        self.int_unique = pd.Int64Index(np.arange(N * 5))
        # cache is_unique
        self.int_unique.is_unique

        self.int = pd.Int64Index(np.arange(N).repeat(5))
        self.float = pd.Float64Index(np.random.randn(N).repeat(5))

        # Convenience naming.
        self.checked_add = pd.core.nanops._checked_add_with_arr

        self.arr = np.arange(1000000)
        self.arrpos = np.arange(1000000)
        self.arrneg = np.arange(-1000000, 0)
        self.arrmixed = np.array([1, -1]).repeat(500000)

    def time_int_factorize(self):
        self.int.factorize()

    def time_float_factorize(self):
        self.int.factorize()

    def time_int_unique_duplicated(self):
        self.int_unique.duplicated()

    def time_int_duplicated(self):
        self.int.duplicated()

    def time_float_duplicated(self):
        self.float.duplicated()

    def time_add_overflow_pos_scalar(self):
        self.checked_add(self.arr, 1)

    def time_add_overflow_neg_scalar(self):
        self.checked_add(self.arr, -1)

    def time_add_overflow_zero_scalar(self):
        self.checked_add(self.arr, 0)

    def time_add_overflow_pos_arr(self):
        self.checked_add(self.arr, self.arrpos)

    def time_add_overflow_neg_arr(self):
        self.checked_add(self.arr, self.arrneg)

    def time_add_overflow_mixed_arr(self):
        self.checked_add(self.arr, self.arrmixed)


class hashing(object):
    goal_time = 0.2

    def setup(self):
        N = 100000

        self.df = pd.DataFrame(
            {'A': pd.Series(tm.makeStringIndex(100).take(
                np.random.randint(0, 100, size=N))),
             'B': pd.Series(tm.makeStringIndex(10000).take(
                 np.random.randint(0, 10000, size=N))),
             'D': np.random.randn(N),
             'E': np.arange(N),
             'F': pd.date_range('20110101', freq='s', periods=N),
             'G': pd.timedelta_range('1 day', freq='s', periods=N),
             })
        self.df['C'] = self.df['B'].astype('category')
        self.df.iloc[10:20] = np.nan

    def time_frame(self):
        self.df.hash()

    def time_series_int(self):
        self.df.E.hash()

    def time_series_string(self):
        self.df.B.hash()

    def time_series_categorical(self):
        self.df.C.hash()

[((22, 19, 22, 37), 'numpy.arange', 'np.arange', ({(22, 29, 22, 36): '1000000'}, {}), '(1000000)', True, 'import numpy as np\n'), ((23, 22, 23, 40), 'numpy.arange', 'np.arange', ({(23, 32, 23, 39): '1000000'}, {}), '(1000000)', True, 'import numpy as np\n'), ((24, 22, 24, 44), 'numpy.arange', 'np.arange', ({(24, 32, 24, 40): '-1000000', (24, 42, 24, 43): '0'}, {}), '(-1000000, 0)', True, 'import numpy as np\n'), ((12, 40, 12, 56), 'numpy.arange', 'np.arange', ({(12, 50, 12, 55): 'N * 5'}, {}), '(N * 5)', True, 'import numpy as np\n'), ((25, 24, 25, 41), 'numpy.array', 'np.array', ({(25, 33, 25, 40): '[1, -1]'}, {}), '([1, -1])', True, 'import numpy as np\n'), ((72, 18, 72, 36), 'numpy.random.randn', 'np.random.randn', ({(72, 34, 72, 35): 'N'}, {}), '(N)', True, 'import numpy as np\n'), ((73, 18, 73, 30), 'numpy.arange', 'np.arange', ({(73, 28, 73, 29): 'N'}, {}), '(N)', True, 'import numpy as np\n'), ((74, 18, 74, 64), 'pandas.date_range', 'pd.date_range', (), '', True, 'import pandas as pd\n'), ((75, 18, 75, 66), 'pandas.timedelta_range', 'pd.timedelta_range', (), '', True, 'import pandas as pd\n'), ((16, 33, 16, 45), 'numpy.arange', 'np.arange', ({(16, 43, 16, 44): 'N'}, {}), '(N)', True, 'import numpy as np\n'), ((17, 37, 17, 55), 'numpy.random.randn', 'np.random.randn', ({(17, 53, 17, 54): 'N'}, {}), '(N)', True, 'import numpy as np\n'), ((69, 16, 69, 49), 'numpy.random.randint', 'np.random.randint', (), '', True, 'import numpy as np\n'), ((71, 17, 71, 52), 'numpy.random.randint', 'np.random.randint', (), '', True, 'import numpy as np\n'), ((68, 28, 68, 51), 'pandas.util.testing.makeStringIndex', 'tm.makeStringIndex', ({(68, 47, 68, 50): '100'}, {}), '(100)', True, 'from pandas.util import testing as tm\n'), ((70, 28, 70, 53), 'pandas.util.testing.makeStringIndex', 'tm.makeStringIndex', ({(70, 47, 70, 52): '10000'}, {}), '(10000)', True, 'from pandas.util import testing as tm\n')]