Python pandas.util.testing.assert_panel_equal() Examples

The following are 30 code examples of pandas.util.testing.assert_panel_equal(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pandas.util.testing , or try the search function .
Example #1
Source File: test_generic.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_numpy_transpose(self):
        msg = "the 'axes' parameter is not supported"

        s = tm.makeFloatSeries()
        tm.assert_series_equal(np.transpose(s), s)

        with pytest.raises(ValueError, match=msg):
            np.transpose(s, axes=1)

        df = tm.makeTimeDataFrame()
        tm.assert_frame_equal(np.transpose(np.transpose(df)), df)

        with pytest.raises(ValueError, match=msg):
            np.transpose(df, axes=1)

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            p = tm.makePanel()
            tm.assert_panel_equal(np.transpose(
                np.transpose(p, axes=(2, 0, 1)),
                axes=(1, 2, 0)), p) 
Example #2
Source File: test_panel.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_constructor_resize(self):
        with catch_warnings(record=True):
            data = self.panel._data
            items = self.panel.items[:-1]
            major = self.panel.major_axis[:-1]
            minor = self.panel.minor_axis[:-1]

            result = Panel(data, items=items,
                           major_axis=major, minor_axis=minor)
            expected = self.panel.reindex(
                items=items, major=major, minor=minor)
            assert_panel_equal(result, expected)

            result = Panel(data, items=items, major_axis=major)
            expected = self.panel.reindex(items=items, major=major)
            assert_panel_equal(result, expected)

            result = Panel(data, items=items)
            expected = self.panel.reindex(items=items)
            assert_panel_equal(result, expected)

            result = Panel(data, minor_axis=minor)
            expected = self.panel.reindex(minor=minor)
            assert_panel_equal(result, expected) 
Example #3
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_reindex_axis_style(self):
        panel = Panel(np.random.rand(5, 5, 5))
        expected0 = Panel(panel.values).iloc[[0, 1]]
        expected1 = Panel(panel.values).iloc[:, [0, 1]]
        expected2 = Panel(panel.values).iloc[:, :, [0, 1]]

        result = panel.reindex([0, 1], axis=0)
        assert_panel_equal(result, expected0)

        result = panel.reindex([0, 1], axis=1)
        assert_panel_equal(result, expected1)

        result = panel.reindex([0, 1], axis=2)
        assert_panel_equal(result, expected2)

        result = panel.reindex([0, 1], axis=2)
        assert_panel_equal(result, expected2) 
Example #4
Source File: test_panel.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_take(self):
        with catch_warnings(record=True):
            # axis == 0
            result = self.panel.take([2, 0, 1], axis=0)
            expected = self.panel.reindex(items=['ItemC', 'ItemA', 'ItemB'])
            assert_panel_equal(result, expected)

            # axis >= 1
            result = self.panel.take([3, 0, 1, 2], axis=2)
            expected = self.panel.reindex(minor=['D', 'A', 'B', 'C'])
            assert_panel_equal(result, expected)

            # neg indicies ok
            expected = self.panel.reindex(minor=['D', 'D', 'B', 'C'])
            result = self.panel.take([3, -1, 1, 2], axis=2)
            assert_panel_equal(result, expected)

            pytest.raises(Exception, self.panel.take, [4, 0, 1, 2], axis=2) 
Example #5
Source File: test_panel.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_constructor_dict_mixed(self):
        with catch_warnings(record=True):
            data = {k: v.values for k, v in self.panel.iteritems()}
            result = Panel(data)
            exp_major = Index(np.arange(len(self.panel.major_axis)))
            tm.assert_index_equal(result.major_axis, exp_major)

            result = Panel(data, items=self.panel.items,
                           major_axis=self.panel.major_axis,
                           minor_axis=self.panel.minor_axis)
            assert_panel_equal(result, self.panel)

            data['ItemC'] = self.panel['ItemC']
            result = Panel(data)
            assert_panel_equal(result, self.panel)

            # corner, blow up
            data['ItemB'] = data['ItemB'][:-1]
            pytest.raises(Exception, Panel, data)

            data['ItemB'] = self.panel['ItemB'].values[:, :-1]
            pytest.raises(Exception, Panel, data) 
Example #6
Source File: test_panel.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_swapaxes(self):
        with catch_warnings(record=True):
            result = self.panel.swapaxes('items', 'minor')
            assert result.items is self.panel.minor_axis

            result = self.panel.swapaxes('items', 'major')
            assert result.items is self.panel.major_axis

            result = self.panel.swapaxes('major', 'minor')
            assert result.major_axis is self.panel.minor_axis

            panel = self.panel.copy()
            result = panel.swapaxes('major', 'minor')
            panel.values[0, 0, 1] = np.nan
            expected = panel.swapaxes('major', 'minor')
            assert_panel_equal(result, expected)

            # this should also work
            result = self.panel.swapaxes(0, 1)
            assert result.items is self.panel.major_axis

            # this works, but return a copy
            result = self.panel.swapaxes('items', 'items')
            assert_panel_equal(self.panel, result)
            assert id(self.panel) != id(result) 
Example #7
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_take(self):
        # axis == 0
        result = self.panel.take([2, 0, 1], axis=0)
        expected = self.panel.reindex(items=['ItemC', 'ItemA', 'ItemB'])
        assert_panel_equal(result, expected)

        # axis >= 1
        result = self.panel.take([3, 0, 1, 2], axis=2)
        expected = self.panel.reindex(minor=['D', 'A', 'B', 'C'])
        assert_panel_equal(result, expected)

        # neg indices ok
        expected = self.panel.reindex(minor=['D', 'D', 'B', 'C'])
        result = self.panel.take([3, -1, 1, 2], axis=2)
        assert_panel_equal(result, expected)

        pytest.raises(Exception, self.panel.take, [4, 0, 1, 2], axis=2) 
Example #8
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_abs(self):

        result = self.panel.abs()
        result2 = abs(self.panel)
        expected = np.abs(self.panel)
        assert_panel_equal(result, expected)
        assert_panel_equal(result2, expected)

        df = self.panel['ItemA']
        result = df.abs()
        result2 = abs(df)
        expected = np.abs(df)
        assert_frame_equal(result, expected)
        assert_frame_equal(result2, expected)

        s = df['A']
        result = s.abs()
        result2 = abs(s)
        expected = np.abs(s)
        assert_series_equal(result, expected)
        assert_series_equal(result2, expected)
        assert result.name == 'A'
        assert result2.name == 'A' 
Example #9
Source File: test_panel.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_reindex_axis_style(self):
        with catch_warnings(record=True):
            panel = Panel(np.random.rand(5, 5, 5))
            expected0 = Panel(panel.values).iloc[[0, 1]]
            expected1 = Panel(panel.values).iloc[:, [0, 1]]
            expected2 = Panel(panel.values).iloc[:, :, [0, 1]]

            result = panel.reindex([0, 1], axis=0)
            assert_panel_equal(result, expected0)

            result = panel.reindex([0, 1], axis=1)
            assert_panel_equal(result, expected1)

            result = panel.reindex([0, 1], axis=2)
            assert_panel_equal(result, expected2)

            result = panel.reindex([0, 1], axis=2)
            assert_panel_equal(result, expected2) 
Example #10
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_constructor_dict_mixed(self):
        data = {k: v.values for k, v in self.panel.iteritems()}
        result = Panel(data)
        exp_major = Index(np.arange(len(self.panel.major_axis)))
        tm.assert_index_equal(result.major_axis, exp_major)

        result = Panel(data, items=self.panel.items,
                       major_axis=self.panel.major_axis,
                       minor_axis=self.panel.minor_axis)
        assert_panel_equal(result, self.panel)

        data['ItemC'] = self.panel['ItemC']
        result = Panel(data)
        assert_panel_equal(result, self.panel)

        # corner, blow up
        data['ItemB'] = data['ItemB'][:-1]
        pytest.raises(Exception, Panel, data)

        data['ItemB'] = self.panel['ItemB'].values[:, :-1]
        pytest.raises(Exception, Panel, data) 
Example #11
Source File: test_panel.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_abs(self):

        with catch_warnings(record=True):
            result = self.panel.abs()
            result2 = abs(self.panel)
            expected = np.abs(self.panel)
            assert_panel_equal(result, expected)
            assert_panel_equal(result2, expected)

            df = self.panel['ItemA']
            result = df.abs()
            result2 = abs(df)
            expected = np.abs(df)
            assert_frame_equal(result, expected)
            assert_frame_equal(result2, expected)

            s = df['A']
            result = s.abs()
            result2 = abs(s)
            expected = np.abs(s)
            assert_series_equal(result, expected)
            assert_series_equal(result2, expected)
            assert result.name == 'A'
            assert result2.name == 'A' 
Example #12
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_to_frame_mixed(self):
        panel = self.panel.fillna(0)
        panel['str'] = 'foo'
        panel['bool'] = panel['ItemA'] > 0

        lp = panel.to_frame()
        wp = lp.to_panel()
        assert wp['bool'].values.dtype == np.bool_
        # Previously, this was mutating the underlying
        # index and changing its name
        assert_frame_equal(wp['bool'], panel['bool'], check_names=False)

        # GH 8704
        # with categorical
        df = panel.to_frame()
        df['category'] = df['str'].astype('category')

        # to_panel
        # TODO: this converts back to object
        p = df.to_panel()
        expected = panel.copy()
        expected['category'] = 'foo'
        assert_panel_equal(p, expected) 
Example #13
Source File: test_datetime_index.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_resample_panel_numpy():
    rng = date_range('1/1/2000', '6/30/2000')
    n = len(rng)

    with catch_warnings(record=True):
        panel = Panel(np.random.randn(3, n, 5),
                      items=['one', 'two', 'three'],
                      major_axis=rng,
                      minor_axis=['a', 'b', 'c', 'd', 'e'])

        result = panel.resample('M', axis=1).apply(lambda x: x.mean(1))
        expected = panel.resample('M', axis=1).mean()
        tm.assert_panel_equal(result, expected)

        panel = panel.swapaxes(1, 2)
        result = panel.resample('M', axis=2).apply(lambda x: x.mean(2))
        expected = panel.resample('M', axis=2).mean()
        tm.assert_panel_equal(result, expected) 
Example #14
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_multiindex_get(self):
        ind = MultiIndex.from_tuples(
            [('a', 1), ('a', 2), ('b', 1), ('b', 2)],
            names=['first', 'second'])
        wp = Panel(np.random.random((4, 5, 5)),
                   items=ind,
                   major_axis=np.arange(5),
                   minor_axis=np.arange(5))
        f1 = wp['a']
        f2 = wp.loc['a']
        assert_panel_equal(f1, f2)

        assert (f1.items == [1, 2]).all()
        assert (f2.items == [1, 2]).all()

        MultiIndex.from_tuples([('a', 1), ('a', 2), ('b', 1)],
                               names=['first', 'second']) 
Example #15
Source File: test_panel.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_select(self):
        with catch_warnings(record=True):
            p = self.panel

            # select items
            result = p.select(lambda x: x in ('ItemA', 'ItemC'), axis='items')
            expected = p.reindex(items=['ItemA', 'ItemC'])
            assert_panel_equal(result, expected)

            # select major_axis
            result = p.select(lambda x: x >= datetime(
                2000, 1, 15), axis='major')
            new_major = p.major_axis[p.major_axis >= datetime(2000, 1, 15)]
            expected = p.reindex(major=new_major)
            assert_panel_equal(result, expected)

            # select minor_axis
            result = p.select(lambda x: x in ('D', 'A'), axis=2)
            expected = p.reindex(minor=['A', 'D'])
            assert_panel_equal(result, expected)

            # corner case, empty thing
            result = p.select(lambda x: x in ('foo', ), axis='items')
            assert_panel_equal(result, p.reindex(items=[])) 
Example #16
Source File: test_generic.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_transpose(self):
        msg = (r"transpose\(\) got multiple values for "
               r"keyword argument 'axes'")
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            # calls implementation in pandas/core/base.py
            tm.assert_series_equal(s.transpose(), s)
        for df in [tm.makeTimeDataFrame()]:
            tm.assert_frame_equal(df.transpose().transpose(), df)

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel()]:
                tm.assert_panel_equal(p.transpose(2, 0, 1)
                                      .transpose(1, 2, 0), p)
                with pytest.raises(TypeError, match=msg):
                    p.transpose(2, 0, 1, axes=(2, 0, 1)) 
Example #17
Source File: test_generic.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_take(self):
        indices = [1, 5, -2, 6, 3, -1]
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries()]:
            out = s.take(indices)
            expected = Series(data=s.values.take(indices),
                              index=s.index.take(indices), dtype=s.dtype)
            tm.assert_series_equal(out, expected)
        for df in [tm.makeTimeDataFrame()]:
            out = df.take(indices)
            expected = DataFrame(data=df.values.take(indices, axis=0),
                                 index=df.index.take(indices),
                                 columns=df.columns)
            tm.assert_frame_equal(out, expected)

        indices = [-3, 2, 0, 1]
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel()]:
                out = p.take(indices)
                expected = Panel(data=p.values.take(indices, axis=0),
                                 items=p.items.take(indices),
                                 major_axis=p.major_axis,
                                 minor_axis=p.minor_axis)
                tm.assert_panel_equal(out, expected) 
Example #18
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_to_xarray(self):
        from xarray import DataArray

        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            p = tm.makePanel()

            result = p.to_xarray()
            assert isinstance(result, DataArray)
            assert len(result.coords) == 3
            assert_almost_equal(list(result.coords.keys()),
                                ['items', 'major_axis', 'minor_axis'])
            assert len(result.dims) == 3

            # idempotency
            assert_panel_equal(result.to_pandas(), p)


# run all the tests, but wrap each in a warning catcher 
Example #19
Source File: test_join.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_panel_join_overlap(self):
        with catch_warnings(record=True):
            panel = tm.makePanel()
            tm.add_nans(panel)

            p1 = panel.loc[['ItemA', 'ItemB', 'ItemC']]
            p2 = panel.loc[['ItemB', 'ItemC']]

            # Expected index is
            #
            # ItemA, ItemB_p1, ItemC_p1, ItemB_p2, ItemC_p2
            joined = p1.join(p2, lsuffix='_p1', rsuffix='_p2')
            p1_suf = p1.loc[['ItemB', 'ItemC']].add_suffix('_p1')
            p2_suf = p2.loc[['ItemB', 'ItemC']].add_suffix('_p2')
            no_overlap = panel.loc[['ItemA']]
            expected = no_overlap.join(p1_suf.join(p2_suf))
            tm.assert_panel_equal(joined, expected) 
Example #20
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_panel_assignment(self):

        with catch_warnings(record=True):
            # GH3777
            wp = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
                       major_axis=date_range('1/1/2000', periods=5),
                       minor_axis=['A', 'B', 'C', 'D'])
            wp2 = Panel(np.random.randn(2, 5, 4), items=['Item1', 'Item2'],
                        major_axis=date_range('1/1/2000', periods=5),
                        minor_axis=['A', 'B', 'C', 'D'])

            # TODO: unused?
            # expected = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]

            with pytest.raises(NotImplementedError):
                wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = wp2.loc[
                    ['Item1', 'Item2'], :, ['A', 'B']]

            # to_assign = wp2.loc[['Item1', 'Item2'], :, ['A', 'B']]
            # wp.loc[['Item1', 'Item2'], :, ['A', 'B']] = to_assign
            # result = wp.loc[['Item1', 'Item2'], :, ['A', 'B']]
            # tm.assert_panel_equal(result,expected) 
Example #21
Source File: test_groupby.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_panel_groupby():
    panel = tm.makePanel()
    tm.add_nans(panel)
    grouped = panel.groupby({'ItemA': 0, 'ItemB': 0, 'ItemC': 1},
                            axis='items')
    agged = grouped.mean()
    agged2 = grouped.agg(lambda x: x.mean('items'))

    tm.assert_panel_equal(agged, agged2)

    tm.assert_index_equal(agged.items, Index([0, 1]))

    grouped = panel.groupby(lambda x: x.month, axis='major')
    agged = grouped.mean()

    exp = Index(sorted(list(set(panel.major_axis.month))))
    tm.assert_index_equal(agged.major_axis, exp)

    grouped = panel.groupby({'A': 0, 'B': 0, 'C': 1, 'D': 1},
                            axis='minor')
    agged = grouped.mean()
    tm.assert_index_equal(agged.minor_axis, Index([0, 1])) 
Example #22
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_update_filtered(self):
        pan = Panel([[[1.5, np.nan, 3.], [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.]],
                     [[1.5, np.nan, 3.], [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.]]])

        other = Panel(
            [[[3.6, 2., np.nan], [np.nan, np.nan, 7]]], items=[1])

        pan.update(other, filter_func=lambda x: x > 2)

        expected = Panel([[[1.5, np.nan, 3.], [1.5, np.nan, 3.],
                           [1.5, np.nan, 3.], [1.5, np.nan, 3.]],
                          [[1.5, np.nan, 3], [1.5, np.nan, 7],
                           [1.5, np.nan, 3.], [1.5, np.nan, 3.]]])

        assert_panel_equal(pan, expected) 
Example #23
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_update_nooverwrite(self):
        pan = Panel([[[1.5, np.nan, 3.], [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.]],
                     [[1.5, np.nan, 3.], [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.]]])

        other = Panel(
            [[[3.6, 2., np.nan], [np.nan, np.nan, 7]]], items=[1])

        pan.update(other, overwrite=False)

        expected = Panel([[[1.5, np.nan, 3], [1.5, np.nan, 3],
                           [1.5, np.nan, 3.], [1.5, np.nan, 3.]],
                          [[1.5, 2., 3.], [1.5, np.nan, 3.],
                           [1.5, np.nan, 3.],
                           [1.5, np.nan, 3.]]])

        assert_panel_equal(pan, expected) 
Example #24
Source File: test_time_grouper.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_panel_aggregation():
    ind = pd.date_range('1/1/2000', periods=100)
    data = np.random.randn(2, len(ind), 4)

    wp = Panel(data, items=['Item1', 'Item2'], major_axis=ind,
               minor_axis=['A', 'B', 'C', 'D'])

    tg = TimeGrouper('M', axis=1)
    _, grouper, _ = tg._get_grouper(wp)
    bingrouped = wp.groupby(grouper)
    binagg = bingrouped.mean()

    def f(x):
        assert (isinstance(x, Panel))
        return x.mean(1)

    result = bingrouped.agg(f)
    tm.assert_panel_equal(result, binagg) 
Example #25
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_update(self):
        pan = Panel([[[1.5, np.nan, 3.], [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.]],
                     [[1.5, np.nan, 3.], [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.],
                      [1.5, np.nan, 3.]]])

        other = Panel(
            [[[3.6, 2., np.nan], [np.nan, np.nan, 7]]], items=[1])

        pan.update(other)

        expected = Panel([[[1.5, np.nan, 3.], [1.5, np.nan, 3.],
                           [1.5, np.nan, 3.], [1.5, np.nan, 3.]],
                          [[3.6, 2., 3], [1.5, np.nan, 7],
                           [1.5, np.nan, 3.],
                           [1.5, np.nan, 3.]]])

        assert_panel_equal(pan, expected) 
Example #26
Source File: test_panel.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_numpy_round(self):
        values = [[[-3.2, 2.2], [0, -4.8213], [3.123, 123.12],
                   [-1566.213, 88.88], [-12, 94.5]],
                  [[-5.82, 3.5], [6.21, -73.272], [-9.087, 23.12],
                   [272.212, -99.99], [23, -76.5]]]
        evalues = [[[float(np.around(i)) for i in j] for j in k]
                   for k in values]
        p = Panel(values, items=['Item1', 'Item2'],
                  major_axis=date_range('1/1/2000', periods=5),
                  minor_axis=['A', 'B'])
        expected = Panel(evalues, items=['Item1', 'Item2'],
                         major_axis=date_range('1/1/2000', periods=5),
                         minor_axis=['A', 'B'])
        result = np.round(p)
        assert_panel_equal(expected, result)

        msg = "the 'out' parameter is not supported"
        with pytest.raises(ValueError, match=msg):
            np.round(p, out=p)

    # removing Panel before NumPy enforces, so just ignore 
Example #27
Source File: test_panel.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_panel_setitem(self):

        with catch_warnings(record=True):
            # GH 7763
            # loc and setitem have setting differences
            np.random.seed(0)
            index = range(3)
            columns = list('abc')

            panel = Panel({'A': DataFrame(np.random.randn(3, 3),
                                          index=index, columns=columns),
                           'B': DataFrame(np.random.randn(3, 3),
                                          index=index, columns=columns),
                           'C': DataFrame(np.random.randn(3, 3),
                                          index=index, columns=columns)})

            replace = DataFrame(np.eye(3, 3), index=range(3), columns=columns)
            expected = Panel({'A': replace, 'B': replace, 'C': replace})

            p = panel.copy()
            for idx in list('ABC'):
                p[idx] = replace
            tm.assert_panel_equal(p, expected)

            p = panel.copy()
            for idx in list('ABC'):
                p.loc[idx, :, :] = replace
            tm.assert_panel_equal(p, expected) 
Example #28
Source File: test_panel.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_reindex_like(self):
        with catch_warnings(record=True):
            # reindex_like
            smaller = self.panel.reindex(items=self.panel.items[:-1],
                                         major=self.panel.major_axis[:-1],
                                         minor=self.panel.minor_axis[:-1])
            smaller_like = self.panel.reindex_like(smaller)
            assert_panel_equal(smaller, smaller_like) 
Example #29
Source File: test_missing.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_isna_isnull(self, isna_f):
        assert not isna_f(1.)
        assert isna_f(None)
        assert isna_f(np.NaN)
        assert float('nan')
        assert not isna_f(np.inf)
        assert not isna_f(-np.inf)

        # series
        for s in [tm.makeFloatSeries(), tm.makeStringSeries(),
                  tm.makeObjectSeries(), tm.makeTimeSeries(),
                  tm.makePeriodSeries()]:
            assert isinstance(isna_f(s), Series)

        # frame
        for df in [tm.makeTimeDataFrame(), tm.makePeriodFrame(),
                   tm.makeMixedDataFrame()]:
            result = isna_f(df)
            expected = df.apply(isna_f)
            tm.assert_frame_equal(result, expected)

        # panel
        with catch_warnings(record=True):
            simplefilter("ignore", FutureWarning)
            for p in [tm.makePanel(), tm.makePeriodPanel(),
                      tm.add_nans(tm.makePanel())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel_equal(result, expected) 
Example #30
Source File: test_panel.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_ffill_bfill(self):
        with catch_warnings(record=True):
            assert_panel_equal(self.panel.ffill(),
                               self.panel.fillna(method='ffill'))
            assert_panel_equal(self.panel.bfill(),
                               self.panel.fillna(method='bfill'))