Ejemplo n.º 1
0
    def test_isna(self):
        ind = Index([3, 2, -999, 4, -999])

        actual = ind.isna()
        expected = Index([False, False, True, False, True], np.dtype(np.bool))

        assert_index_equal(actual, expected)
Ejemplo n.º 2
0
    def test_op_scalar(self, operation, expected_data, data_f32):
        ind = Index(data_f32)

        actual = eval('ind {} 2'.format(operation))
        expected = Index(expected_data, np.dtype(np.float32))

        assert_index_equal(actual, expected)
Ejemplo n.º 3
0
    def test_dropna(self):
        ind = Index([3, 2, -999, 4, -999])

        actual = ind.dropna()
        expected = Index([3, 2, 4], np.dtype(np.int64))

        assert_index_equal(actual, expected)
Ejemplo n.º 4
0
    def test_fillna(self):
        ind = Index([3, 2, -999, 4, -999])

        actual = ind.fillna(15)
        expected = Index([3, 2, 15, 4, 15], np.dtype(np.int64))

        assert_index_equal(actual, expected)
Ejemplo n.º 5
0
    def test_join(self):
        df1 = DataFrame(
            OrderedDict(
                (('a', np.arange(5)), ('b', np.arange(1, 6,
                                                      dtype=np.float64)))),
            Index(np.arange(0, 5)))
        df2 = DataFrame(
            OrderedDict(
                (('b', np.arange(3, 6,
                                 dtype=np.float32)), ('c', np.arange(4, 7)))),
            Index(np.array(np.array([1, 3, 5]))))

        actual = df1.join(df2, lsuffix='_x')
        expected = DataFrame(
            OrderedDict((('a', np.arange(5)), ('b_x',
                                               np.arange(1,
                                                         6,
                                                         dtype=np.float64)),
                         ('b',
                          Series(
                              np.array([-999., 3., -999., 4., -999.],
                                       dtype=np.float32))),
                         ('c', np.array([-999, 4, -999, 5, -999])))),
            Index(np.arange(0, 5), np.dtype(np.int64), 'index'))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 6
0
    def test_op_array(self, operation, expected_data, data_f32, op_array_other):
        data = Index(data_f32)

        actual = eval('data {} op_array_other'.format(operation))
        expected = Index(expected_data, np.dtype(np.float32))

        assert_index_equal(actual, expected)
Ejemplo n.º 7
0
    def test_set_multi_index(self, df_small, data_f32, data_i64, data_str):
        actual = df_small.set_index(['b', 'c'])
        expected = DataFrame({'a': data_f32},
                             MultiIndex([
                                 Index(data_i64, np.dtype(np.int64), 'b'),
                                 Index(data_str, name='c')
                             ], ['b', 'c']))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 8
0
    def test_slice(self, data_f32, index_i64):
        mi = MultiIndex([data_f32, index_i64])

        actual = mi[1:3]
        expected = MultiIndex([
            Index(np.array([2, 3], dtype=np.float32), np.dtype(np.float32)),
            Index(np.array([1, 2], dtype=np.int64), np.dtype(np.int64))
        ])

        assert_multiindex_equal(actual, expected)
Ejemplo n.º 9
0
    def test_filter(self, data_f32, index_i64):
        mi = MultiIndex([data_f32, index_i64])

        actual = mi[Index(np.array([False, True, True, False, False]))]
        expected = MultiIndex([
            Index(np.array([2, 3], dtype=np.float32), np.dtype(np.float32)),
            Index(np.array([1, 2], dtype=np.int64), np.dtype(np.int64))
        ])

        assert_multiindex_equal(actual, expected)
Ejemplo n.º 10
0
    def test_groupby_multi(self, index_i64, series_i64, df_dupl):
        actual = df_dupl.groupby(['a', 'b']).min()
        expected = DataFrame(
            OrderedDict({'c': [1, 2, 4, 5]}),
            MultiIndex([
                Index(np.array([0, 1, 2, 3], dtype=np.float32),
                      np.dtype(np.float32), 'a'),
                Index([4, 5, 6, 6], np.dtype(np.int64), 'b')
            ], ['a', 'b']))

        assert_dataframe_equal(actual, expected, sort=True)
Ejemplo n.º 11
0
    def test_dropna(self, index_i64):
        sr = Series([3, 2, -999, 4, -999], index_i64, dtype=np.dtype(np.int64))

        actual = sr.dropna()
        expected = Series([3, 2, 4], Index([0, 1, 3]), np.dtype(np.int64))

        assert_series_equal(actual, expected)
Ejemplo n.º 12
0
    def test_filter(self, series_i64):
        actual = series_i64[series_i64 != 2]
        expected = Series(np.array([1, 3, 4, 5]), Index(np.array([0, 2, 3,
                                                                  4])),
                          np.dtype(np.int64))

        assert_series_equal(actual, expected)
Ejemplo n.º 13
0
    def test_len_lazy(self, data_i64_lazy):
        ind = Index(data_i64_lazy, np.dtype(np.int64))

        actual = len(ind)
        expected = 5

        assert actual == expected
Ejemplo n.º 14
0
    def test_from_pandas_index(self, index_i64):
        pandas_index = pd.Index([0, 1, 2, 3, 4])

        actual = Index.from_pandas(pandas_index)
        expected = index_i64

        assert_index_equal(actual, expected)
Ejemplo n.º 15
0
    def test_iloc_indices_missing(self, series_f32):
        indices = Series(np.array([0, 3, 5]))

        actual = series_f32.iloc._iloc_with_missing(indices.weld_expr)
        expected = Series(np.array([1, 4, -999], dtype=np.float32),
                          Index(np.array([0, 3, -999])), np.dtype(np.float32))

        assert_series_equal(actual, expected)
Ejemplo n.º 16
0
    def test_iloc_indices(self, series_f32):
        indices = Series(np.array([0, 3, 4]))

        actual = series_f32.iloc[indices]
        expected = Series(np.array([1, 4, 5], dtype=np.float32),
                          Index(np.array([0, 3, 4])), np.dtype(np.float32))

        assert_series_equal(actual, expected)
Ejemplo n.º 17
0
    def test_filter_str(self, series_str):
        actual = series_str[series_str != 'Abc']
        expected = Series(
            np.array(['a', 'goosfraba', '   dC  ', 'secrETariat'],
                     dtype=np.bytes_), Index(np.array([0, 2, 3, 4])),
            np.dtype(np.bytes_))

        assert_series_equal(actual, expected)
Ejemplo n.º 18
0
    def test_sort_values(self, data_f32, series_i64, data_i64):
        data = [np.array([3, 1, 2, 5, 4], dtype=np.float32), series_i64]
        df = DataFrame(OrderedDict((('a', data[0]), ('b', data[1]))),
                       Index(data_i64))

        actual = df.sort_values('a')

        expected_index = Index(np.array([2, 3, 1, 5, 4]), np.dtype(np.int64))
        expected_data = [
            Series(data_f32, expected_index, np.dtype(np.float32), 'a'),
            Series(np.array([2, 3, 1, 5, 4], dtype=np.int64), expected_index,
                   np.dtype(np.int64), 'b')
        ]
        expected = DataFrame(
            OrderedDict((('a', expected_data[0]), ('b', expected_data[1]))),
            expected_index)

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 19
0
    def test_agg(self, series_f32):
        aggregations = ['max', 'var', 'count', 'mean']
        actual = series_f32.agg(aggregations)

        expected = Series(np.array([5, 2.5, 5, 3], dtype=np.float64),
                          Index(np.array(aggregations, dtype=np.bytes_)),
                          np.dtype(np.float64))

        assert_series_equal(actual, expected)
Ejemplo n.º 20
0
    def test_dropna(self):
        mi = MultiIndex([[0, -999, 2, -999],
                         Index([1., -999., -999., 3.],
                               dtype=np.dtype(np.float64))])

        actual = mi.dropna()
        expected = MultiIndex([[0], [1.]])

        assert_multiindex_equal(actual, expected)
Ejemplo n.º 21
0
    def test_sort_index_index_descending(self, data_f32, series_i64):
        data = [data_f32, series_i64]
        df = DataFrame(OrderedDict((('a', data[0]), ('b', data[1]))),
                       Index(np.array([3, 1, 2, 5, 4])))

        actual = df.sort_index(ascending=False)

        expected_index = Index(np.arange(5, 0, -1), np.dtype(np.int64))
        expected_data = [
            Series(np.array([4, 5, 1, 3, 2], dtype=np.float32), expected_index,
                   np.dtype(np.float32), 'a'),
            Series(np.array([4, 5, 1, 3, 2], dtype=np.int64), expected_index,
                   np.dtype(np.int64), 'b')
        ]
        expected = DataFrame(
            OrderedDict((('a', expected_data[0]), ('b', expected_data[1]))),
            expected_index)

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 22
0
    def test_merge_unsorted_unique_single_on_inner(self, df2, data_f32,
                                                   index_i64_2):
        df1 = DataFrame(
            OrderedDict((('a', Series(np.array([3, 2, 0, 4, 1]))),
                         ('b', np.array([4, 3, 1, 5, 2], dtype=np.float32)))),
            Index([5, 4, 2, 6, 3]))

        actual = df1.merge(df2, on='a')
        expected = DataFrame(
            OrderedDict(
                (('index', np.array([3, 5])), ('b_x',
                                               np.array([2, 4],
                                                        dtype=np.float32)),
                 ('d', np.array(['abc', 'def'], dtype=np.dtype('|S4'))),
                 ('b_y', Series(np.arange(3, 5, dtype=np.float32))),
                 ('c', np.arange(4, 6)))),
            Index(np.array([1, 3]), np.dtype(np.int64), 'a'))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 23
0
    def test_agg(self, df_small):
        aggregations = ['max', 'var', 'count', 'mean']

        actual = df_small.agg(aggregations)
        expected = DataFrame(
            OrderedDict((('a', np.array([5, 2.5, 5, 3], dtype=np.float64)),
                         ('b', np.array([5, 2.5, 5, 3], dtype=np.float64)))),
            Index(np.array(aggregations, dtype=np.bytes_),
                  np.dtype(np.bytes_)))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 24
0
    def test_head(self, df_small):
        actual = df_small.head(2)
        data = [1, 2]
        expected = DataFrame(
            OrderedDict(
                (('a', np.array(data,
                                dtype=np.float32)), ('b', np.array(data)),
                 ('c', np.array(['a', 'Abc'], dtype=np.dtype('|S11'))))),
            Index(np.array([0, 1])))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 25
0
    def test_tail(self, df_small):
        actual = df_small.tail(2)
        data = [4, 5]
        expected = DataFrame(
            OrderedDict(
                (('a', np.array(data, dtype=np.float32)),
                 ('b', np.array(data)), ('c',
                                         np.array(['   dC  ', 'secrETariat'],
                                                  dtype=np.dtype('|S11'))))),
            Index(np.array([3, 4])))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 26
0
    def test_filter(self, df_small):
        actual = df_small[Series(np.array([False, True, True, False, False]))]
        data = [2, 3]
        expected = DataFrame(
            OrderedDict(
                (('a', np.array(data,
                                dtype=np.float32)), ('b', np.array(data)),
                 ('c', np.array(['Abc', 'goosfraba'],
                                dtype=np.dtype('|S11'))))),
            Index(np.array([1, 2])))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 27
0
    def test_dropna(self, index_i64):
        df = DataFrame(
            OrderedDict((('a', np.array([0, 1, -999, 2, -999],
                                        dtype=np.float32)),
                         ('b', [4, -999, -999, 6, 6]))), index_i64)

        actual = df.dropna()
        expected = DataFrame(
            OrderedDict((('a', np.array([0, 2],
                                        dtype=np.float32)), ('b', [4, 6]))),
            Index([0, 3]))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 28
0
    def test_drop_duplicates_subset(self, index_i64):
        df = DataFrame(
            OrderedDict(
                (('a', np.array([0, 1, 1, 2, 3],
                                dtype=np.float32)), ('b', [4, 5, 5, 6, 6]))),
            index_i64)

        actual = df.drop_duplicates(subset=['b'])
        expected = DataFrame(
            OrderedDict((('a', np.array([0, 1, 2],
                                        dtype=np.float32)), ('b', [4, 5, 6]))),
            Index([0, 1, 3]))

        assert_dataframe_equal(actual, expected, sort=True)
Ejemplo n.º 29
0
    def test_setitem_alignment_needed(self, data_f32, index_i64):
        df = DataFrame({'a': data_f32}, index_i64)

        df['b'] = Series(np.array([4, 7, 5, 6, 8]),
                         Index(np.array([0, 3, 1, 2, 5])))
        actual = df
        expected = DataFrame({
            'a': data_f32,
            'b': np.array([4, 5, 6, 7, -999])
        }, index_i64)

        # so is WeldObject which was aligned
        assert not isinstance(df['b'].values, np.ndarray)

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 30
0
    def test_iloc_indices(self, df_small):
        indices = Series(np.array([0, 2, 3]))

        actual = df_small.iloc[indices]
        data = [1, 3, 4]
        expected = DataFrame(
            OrderedDict(
                (('a', np.array(data,
                                dtype=np.float32)), ('b', np.array(data)),
                 ('c',
                  np.array(['a', 'goosfraba', '   dC  '],
                           dtype=np.dtype('|S11'))))),
            Index(np.array([0, 2, 3])))

        assert_dataframe_equal(actual, expected)