当前位置: 首页>>代码示例>>Python>>正文


Python testing.assert_panel_equal方法代码示例

本文整理汇总了Python中pandas.util.testing.assert_panel_equal方法的典型用法代码示例。如果您正苦于以下问题:Python testing.assert_panel_equal方法的具体用法?Python testing.assert_panel_equal怎么用?Python testing.assert_panel_equal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas.util.testing的用法示例。


在下文中一共展示了testing.assert_panel_equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_abs

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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' 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_panel.py

示例2: test_constructor_dict_mixed

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_panel.py

示例3: test_reindex_axis_style

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_panel.py

示例4: test_take

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_panel.py

示例5: test_to_frame_mixed

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_panel.py

示例6: test_numpy_round

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_panel.py

示例7: test_multiindex_get

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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']) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_panel.py

示例8: test_update

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_panel.py

示例9: test_update_nooverwrite

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,代码来源:test_panel.py

示例10: test_update_filtered

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_panel.py

示例11: test_panel_join_overlap

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_join.py

示例12: test_to_xarray

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:test_panel.py

示例13: test_transpose

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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)) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:19,代码来源:test_generic.py

示例14: test_numpy_transpose

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:test_generic.py

示例15: test_take

# 需要导入模块: from pandas.util import testing [as 别名]
# 或者: from pandas.util.testing import assert_panel_equal [as 别名]
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) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:test_generic.py


注:本文中的pandas.util.testing.assert_panel_equal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。