Ejemplo n.º 1
0
    def test_from_pandas_multiindex(self):
        pandas_index = pd.MultiIndex.from_product([[0, 1], [2., 3.]])

        actual = MultiIndex.from_pandas(pandas_index)
        expected = MultiIndex([[0, 0, 1, 1], [2., 3., 2., 3.]])

        assert_multiindex_equal(actual, expected)
Ejemplo n.º 2
0
    def test_to_pandas_multiindex(self):
        data = [[0, 0, 1, 1], [2., 3., 2., 3.]]
        mi = MultiIndex(data)

        actual = mi.to_pandas()
        expected = pd.MultiIndex.from_arrays(data)

        assert actual.equals(expected)
Ejemplo n.º 3
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.º 4
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.º 5
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.º 6
0
    def test_len_raw(self, data_f32, data_i64):
        ind = MultiIndex([data_f32, data_i64])

        actual = len(ind)
        expected = 5

        assert 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_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.º 9
0
    def test_reset_multi_index(self, data_f32, data_i64, data_str, index_i64,
                               names, expected_names):
        df = DataFrame(OrderedDict({'c': data_str}),
                       MultiIndex([data_f32, data_i64], names=names))

        actual = df.reset_index()
        expected = DataFrame(
            OrderedDict(((expected_names[0], data_f32),
                         (expected_names[1], data_i64), ('c', data_str))),
            index_i64)

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 10
0
    def test_merge_sorted_unique_multi_on_inner(self, df1, df2):
        actual = df1.merge(df2, on=['a', 'b'], is_on_sorted=True)
        expected = DataFrame(
            OrderedDict(
                (('index', np.array([5])), ('d',
                                            np.array(['def'],
                                                     dtype=np.dtype('|S4'))),
                 ('c', np.array([5])))),
            MultiIndex(
                [np.array([3]), np.array([4], dtype=np.float32)], ['a', 'b']))

        assert_dataframe_equal(actual, expected)
Ejemplo n.º 11
0
    def test_evaluate(self, data_f32, index_i64):
        actual = MultiIndex([data_f32, index_i64]).evaluate()
        expected = MultiIndex(
            [Index(data_f32, np.dtype(np.float32)), index_i64])

        assert_multiindex_equal(actual, expected)
Ejemplo n.º 12
0
def df2():
    return DataFrame(OrderedDict((('b', np.arange(3, 6, dtype=np.float32)), ('c', np.arange(4, 7)))),
                     MultiIndex([np.array([1, 3, 5]),
                                 Index(np.array(['abc', 'def', 'efgh'], dtype=np.bytes_))],
                                ['a', 'd']))