Python pandas.Panel.from_dict() Examples

The following are 13 code examples of pandas.Panel.from_dict(). 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.Panel , or try the search function .
Example #1
Source Project: recruit   Author: Frank-qlu   File: test_frame.py    License: Apache License 2.0 6 votes vote down vote up
def test_stack_sparse_frame(self, float_frame, float_frame_int_kind,
                                float_frame_fill0, float_frame_fill2):
        def _check(frame):
            dense_frame = frame.to_dense()  # noqa

            wp = Panel.from_dict({'foo': frame})
            from_dense_lp = wp.to_frame()

            from_sparse_lp = spf.stack_sparse_frame(frame)

            tm.assert_numpy_array_equal(from_dense_lp.values,
                                        from_sparse_lp.values)

        _check(float_frame)
        _check(float_frame_int_kind)

        # for now
        pytest.raises(Exception, _check, float_frame_fill0)
        pytest.raises(Exception, _check, float_frame_fill2) 
Example #2
Source Project: vnpy_crypto   Author: birforce   File: test_frame.py    License: MIT License 6 votes vote down vote up
def test_stack_sparse_frame(self):
        with catch_warnings(record=True):

            def _check(frame):
                dense_frame = frame.to_dense()  # noqa

                wp = Panel.from_dict({'foo': frame})
                from_dense_lp = wp.to_frame()

                from_sparse_lp = spf.stack_sparse_frame(frame)

                tm.assert_numpy_array_equal(from_dense_lp.values,
                                            from_sparse_lp.values)

            _check(self.frame)
            _check(self.iframe)

            # for now
            pytest.raises(Exception, _check, self.zframe)
            pytest.raises(Exception, _check, self.fill_frame) 
Example #3
Source Project: Computable   Author: ktraunmueller   File: test_sparse.py    License: MIT License 6 votes vote down vote up
def test_stack_sparse_frame(self):
        def _check(frame):
            dense_frame = frame.to_dense()

            wp = Panel.from_dict({'foo': frame})
            from_dense_lp = wp.to_frame()

            from_sparse_lp = spf.stack_sparse_frame(frame)

            self.assert_(np.array_equal(from_dense_lp.values,
                                        from_sparse_lp.values))

        _check(self.frame)
        _check(self.iframe)

        # for now
        self.assertRaises(Exception, _check, self.zframe)
        self.assertRaises(Exception, _check, self.fill_frame) 
Example #4
Source Project: predictive-maintenance-using-machine-learning   Author: awslabs   File: test_frame.py    License: Apache License 2.0 6 votes vote down vote up
def test_stack_sparse_frame(self, float_frame, float_frame_int_kind,
                                float_frame_fill0, float_frame_fill2):
        def _check(frame):
            dense_frame = frame.to_dense()  # noqa

            wp = Panel.from_dict({'foo': frame})
            from_dense_lp = wp.to_frame()

            from_sparse_lp = spf.stack_sparse_frame(frame)

            tm.assert_numpy_array_equal(from_dense_lp.values,
                                        from_sparse_lp.values)

        _check(float_frame)
        _check(float_frame_int_kind)

        # for now
        pytest.raises(Exception, _check, float_frame_fill0)
        pytest.raises(Exception, _check, float_frame_fill2) 
Example #5
Source Project: elasticintel   Author: securityclippy   File: test_frame.py    License: GNU General Public License v3.0 6 votes vote down vote up
def test_stack_sparse_frame(self):
        with catch_warnings(record=True):

            def _check(frame):
                dense_frame = frame.to_dense()  # noqa

                wp = Panel.from_dict({'foo': frame})
                from_dense_lp = wp.to_frame()

                from_sparse_lp = spf.stack_sparse_frame(frame)

                tm.assert_numpy_array_equal(from_dense_lp.values,
                                            from_sparse_lp.values)

            _check(self.frame)
            _check(self.iframe)

            # for now
            pytest.raises(Exception, _check, self.zframe)
            pytest.raises(Exception, _check, self.fill_frame) 
Example #6
Source Project: coffeegrindsize   Author: jgagneastro   File: test_frame.py    License: MIT License 6 votes vote down vote up
def test_stack_sparse_frame(self, float_frame, float_frame_int_kind,
                                float_frame_fill0, float_frame_fill2):
        def _check(frame):
            dense_frame = frame.to_dense()  # noqa

            wp = Panel.from_dict({'foo': frame})
            from_dense_lp = wp.to_frame()

            from_sparse_lp = spf.stack_sparse_frame(frame)

            tm.assert_numpy_array_equal(from_dense_lp.values,
                                        from_sparse_lp.values)

        _check(float_frame)
        _check(float_frame_int_kind)

        # for now
        pytest.raises(Exception, _check, float_frame_fill0)
        pytest.raises(Exception, _check, float_frame_fill2) 
Example #7
Source Project: twitter-stock-recommendation   Author: alvarobartt   File: test_frame.py    License: MIT License 6 votes vote down vote up
def test_stack_sparse_frame(self):
        with catch_warnings(record=True):

            def _check(frame):
                dense_frame = frame.to_dense()  # noqa

                wp = Panel.from_dict({'foo': frame})
                from_dense_lp = wp.to_frame()

                from_sparse_lp = spf.stack_sparse_frame(frame)

                tm.assert_numpy_array_equal(from_dense_lp.values,
                                            from_sparse_lp.values)

            _check(self.frame)
            _check(self.iframe)

            # for now
            pytest.raises(Exception, _check, self.zframe)
            pytest.raises(Exception, _check, self.fill_frame) 
Example #8
Source Project: Computable   Author: ktraunmueller   File: test_sparse.py    License: MIT License 5 votes vote down vote up
def test_from_dict(self):
        fd = SparsePanel.from_dict(self.data_dict)
        assert_sp_panel_equal(fd, self.panel) 
Example #9
Source Project: Computable   Author: ktraunmueller   File: test_sparse.py    License: MIT License 5 votes vote down vote up
def test_dense_to_sparse(self):
        wp = Panel.from_dict(self.data_dict)
        dwp = wp.to_sparse()
        tm.assert_isinstance(dwp['ItemA']['A'], SparseSeries) 
Example #10
Source Project: Computable   Author: ktraunmueller   File: test_sparse.py    License: MIT License 5 votes vote down vote up
def test_to_dense(self):
        dwp = self.panel.to_dense()
        dwp2 = Panel.from_dict(self.data_dict)
        assert_panel_equal(dwp, dwp2) 
Example #11
Source Project: Computable   Author: ktraunmueller   File: test_fama_macbeth.py    License: MIT License 5 votes vote down vote up
def testFamaMacBethRolling(self):
        # self.checkFamaMacBethExtended('rolling', self.panel_x, self.panel_y,
        #                               nw_lags_beta=2)

        # df = DataFrame(np.random.randn(50, 10))
        x = dict((k, DataFrame(np.random.randn(50, 10))) for k in 'abcdefg')
        x = Panel.from_dict(x)
        y = (DataFrame(np.random.randn(50, 10)) +
             DataFrame(0.01 * np.random.randn(50, 10)))
        self.checkFamaMacBethExtended('rolling', x, y, nw_lags_beta=2)
        self.checkFamaMacBethExtended('expanding', x, y, nw_lags_beta=2) 
Example #12
Source Project: Computable   Author: ktraunmueller   File: test_merge.py    License: MIT License 5 votes vote down vote up
def test_merge_nosort(self):
        # #2098, anything to do?

        from datetime import datetime

        d = {"var1": np.random.randint(0, 10, size=10),
             "var2": np.random.randint(0, 10, size=10),
             "var3": [datetime(2012, 1, 12), datetime(2011, 2, 4),
                      datetime(
                      2010, 2, 3), datetime(2012, 1, 12),
                      datetime(
                      2011, 2, 4), datetime(2012, 4, 3),
                      datetime(
                      2012, 3, 4), datetime(2008, 5, 1),
                      datetime(2010, 2, 3), datetime(2012, 2, 3)]}
        df = DataFrame.from_dict(d)
        var3 = df.var3.unique()
        var3.sort()
        new = DataFrame.from_dict({"var3": var3,
                                   "var8": np.random.random(7)})

        result = df.merge(new, on="var3", sort=False)
        exp = merge(df, new, on='var3', sort=False)
        assert_frame_equal(result, exp)

        self.assert_((df.var3.unique() == result.var3.unique()).all()) 
Example #13
Source Project: Computable   Author: ktraunmueller   File: test_merge.py    License: MIT License 5 votes vote down vote up
def test_panel_join_many(self):
        tm.K = 10
        panel = tm.makePanel()
        tm.K = 4

        panels = [panel.ix[:2], panel.ix[2:6], panel.ix[6:]]

        joined = panels[0].join(panels[1:])
        tm.assert_panel_equal(joined, panel)

        panels = [panel.ix[:2, :-5], panel.ix[2:6, 2:], panel.ix[6:, 5:-7]]

        data_dict = {}
        for p in panels:
            data_dict.update(compat.iteritems(p))

        joined = panels[0].join(panels[1:], how='inner')
        expected = Panel.from_dict(data_dict, intersect=True)
        tm.assert_panel_equal(joined, expected)

        joined = panels[0].join(panels[1:], how='outer')
        expected = Panel.from_dict(data_dict, intersect=False)
        tm.assert_panel_equal(joined, expected)

        # edge cases
        self.assertRaises(ValueError, panels[0].join, panels[1:],
                          how='outer', lsuffix='foo', rsuffix='bar')
        self.assertRaises(ValueError, panels[0].join, panels[1:],
                          how='right')