Python pandas.util.testing.makePeriodPanel() Examples

The following are 11 code examples of pandas.util.testing.makePeriodPanel(). 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_panel.py    From recruit with Apache License 2.0 5 votes vote down vote up
def test_tshift(self):
        # PeriodIndex
        ps = tm.makePeriodPanel()
        shifted = ps.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_panel_equal(unshifted, ps)

        shifted2 = ps.tshift(freq='B')
        assert_panel_equal(shifted, shifted2)

        shifted3 = ps.tshift(freq=BDay())
        assert_panel_equal(shifted, shifted3)

        with pytest.raises(ValueError, match='does not match'):
            ps.tshift(freq='M')

        # DatetimeIndex
        panel = make_test_panel()
        shifted = panel.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_panel_equal(panel, unshifted)

        shifted2 = panel.tshift(freq=panel.major_axis.freq)
        assert_panel_equal(shifted, shifted2)

        inferred_ts = Panel(panel.values, items=panel.items,
                            major_axis=Index(np.asarray(panel.major_axis)),
                            minor_axis=panel.minor_axis)
        shifted = inferred_ts.tshift(1)
        unshifted = shifted.tshift(-1)
        assert_panel_equal(shifted, panel.tshift(1))
        assert_panel_equal(unshifted, inferred_ts)

        no_freq = panel.iloc[:, [0, 5, 7], :]
        pytest.raises(ValueError, no_freq.tshift) 
Example #2
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 #3
Source File: test_panel.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_tshift(self):
        # PeriodIndex
        with catch_warnings(record=True):
            ps = tm.makePeriodPanel()
            shifted = ps.tshift(1)
            unshifted = shifted.tshift(-1)

            assert_panel_equal(unshifted, ps)

            shifted2 = ps.tshift(freq='B')
            assert_panel_equal(shifted, shifted2)

            shifted3 = ps.tshift(freq=BDay())
            assert_panel_equal(shifted, shifted3)

            tm.assert_raises_regex(ValueError, 'does not match',
                                   ps.tshift, freq='M')

            # DatetimeIndex
            panel = make_test_panel()
            shifted = panel.tshift(1)
            unshifted = shifted.tshift(-1)

            assert_panel_equal(panel, unshifted)

            shifted2 = panel.tshift(freq=panel.major_axis.freq)
            assert_panel_equal(shifted, shifted2)

            inferred_ts = Panel(panel.values, items=panel.items,
                                major_axis=Index(np.asarray(panel.major_axis)),
                                minor_axis=panel.minor_axis)
            shifted = inferred_ts.tshift(1)
            unshifted = shifted.tshift(-1)
            assert_panel_equal(shifted, panel.tshift(1))
            assert_panel_equal(unshifted, inferred_ts)

            no_freq = panel.iloc[:, [0, 5, 7], :]
            pytest.raises(ValueError, no_freq.tshift) 
Example #4
Source File: test_missing.py    From vnpy_crypto with MIT License 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):
            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 #5
Source File: test_panel.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_tshift(self):
        # PeriodIndex
        ps = tm.makePeriodPanel()
        shifted = ps.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_panel_equal(unshifted, ps)

        shifted2 = ps.tshift(freq='B')
        assert_panel_equal(shifted, shifted2)

        shifted3 = ps.tshift(freq=BDay())
        assert_panel_equal(shifted, shifted3)

        with pytest.raises(ValueError, match='does not match'):
            ps.tshift(freq='M')

        # DatetimeIndex
        panel = make_test_panel()
        shifted = panel.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_panel_equal(panel, unshifted)

        shifted2 = panel.tshift(freq=panel.major_axis.freq)
        assert_panel_equal(shifted, shifted2)

        inferred_ts = Panel(panel.values, items=panel.items,
                            major_axis=Index(np.asarray(panel.major_axis)),
                            minor_axis=panel.minor_axis)
        shifted = inferred_ts.tshift(1)
        unshifted = shifted.tshift(-1)
        assert_panel_equal(shifted, panel.tshift(1))
        assert_panel_equal(unshifted, inferred_ts)

        no_freq = panel.iloc[:, [0, 5, 7], :]
        pytest.raises(ValueError, no_freq.tshift) 
Example #6
Source File: test_missing.py    From predictive-maintenance-using-machine-learning 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 #7
Source File: test_panel.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_tshift(self):
        # PeriodIndex
        with catch_warnings(record=True):
            ps = tm.makePeriodPanel()
            shifted = ps.tshift(1)
            unshifted = shifted.tshift(-1)

            assert_panel_equal(unshifted, ps)

            shifted2 = ps.tshift(freq='B')
            assert_panel_equal(shifted, shifted2)

            shifted3 = ps.tshift(freq=BDay())
            assert_panel_equal(shifted, shifted3)

            tm.assert_raises_regex(ValueError, 'does not match',
                                   ps.tshift, freq='M')

            # DatetimeIndex
            panel = make_test_panel()
            shifted = panel.tshift(1)
            unshifted = shifted.tshift(-1)

            assert_panel_equal(panel, unshifted)

            shifted2 = panel.tshift(freq=panel.major_axis.freq)
            assert_panel_equal(shifted, shifted2)

            inferred_ts = Panel(panel.values, items=panel.items,
                                major_axis=Index(np.asarray(panel.major_axis)),
                                minor_axis=panel.minor_axis)
            shifted = inferred_ts.tshift(1)
            unshifted = shifted.tshift(-1)
            assert_panel_equal(shifted, panel.tshift(1))
            assert_panel_equal(unshifted, inferred_ts)

            no_freq = panel.iloc[:, [0, 5, 7], :]
            pytest.raises(ValueError, no_freq.tshift) 
Example #8
Source File: test_missing.py    From elasticintel with GNU General Public License v3.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):
            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)

        # panel 4d
        with catch_warnings(record=True):
            for p in [tm.makePanel4D(), tm.add_nans_panel4d(tm.makePanel4D())]:
                result = isna_f(p)
                expected = p.apply(isna_f)
                tm.assert_panel4d_equal(result, expected) 
Example #9
Source File: test_panel.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_tshift(self):
        # PeriodIndex
        ps = tm.makePeriodPanel()
        shifted = ps.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_panel_equal(unshifted, ps)

        shifted2 = ps.tshift(freq='B')
        assert_panel_equal(shifted, shifted2)

        shifted3 = ps.tshift(freq=BDay())
        assert_panel_equal(shifted, shifted3)

        with pytest.raises(ValueError, match='does not match'):
            ps.tshift(freq='M')

        # DatetimeIndex
        panel = make_test_panel()
        shifted = panel.tshift(1)
        unshifted = shifted.tshift(-1)

        assert_panel_equal(panel, unshifted)

        shifted2 = panel.tshift(freq=panel.major_axis.freq)
        assert_panel_equal(shifted, shifted2)

        inferred_ts = Panel(panel.values, items=panel.items,
                            major_axis=Index(np.asarray(panel.major_axis)),
                            minor_axis=panel.minor_axis)
        shifted = inferred_ts.tshift(1)
        unshifted = shifted.tshift(-1)
        assert_panel_equal(shifted, panel.tshift(1))
        assert_panel_equal(unshifted, inferred_ts)

        no_freq = panel.iloc[:, [0, 5, 7], :]
        pytest.raises(ValueError, no_freq.tshift) 
Example #10
Source File: test_panel.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_tshift(self):
        # PeriodIndex
        with catch_warnings(record=True):
            ps = tm.makePeriodPanel()
            shifted = ps.tshift(1)
            unshifted = shifted.tshift(-1)

            assert_panel_equal(unshifted, ps)

            shifted2 = ps.tshift(freq='B')
            assert_panel_equal(shifted, shifted2)

            shifted3 = ps.tshift(freq=BDay())
            assert_panel_equal(shifted, shifted3)

            tm.assert_raises_regex(ValueError, 'does not match',
                                   ps.tshift, freq='M')

            # DatetimeIndex
            panel = make_test_panel()
            shifted = panel.tshift(1)
            unshifted = shifted.tshift(-1)

            assert_panel_equal(panel, unshifted)

            shifted2 = panel.tshift(freq=panel.major_axis.freq)
            assert_panel_equal(shifted, shifted2)

            inferred_ts = Panel(panel.values, items=panel.items,
                                major_axis=Index(np.asarray(panel.major_axis)),
                                minor_axis=panel.minor_axis)
            shifted = inferred_ts.tshift(1)
            unshifted = shifted.tshift(-1)
            assert_panel_equal(shifted, panel.tshift(1))
            assert_panel_equal(unshifted, inferred_ts)

            no_freq = panel.iloc[:, [0, 5, 7], :]
            pytest.raises(ValueError, no_freq.tshift) 
Example #11
Source File: test_missing.py    From twitter-stock-recommendation with MIT License 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):
            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)