Python pandas.util.testing.round_trip_pickle() Examples

The following are 30 code examples of pandas.util.testing.round_trip_pickle(). 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_timeseries.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_pickle(self):

        # GH4606
        p = tm.round_trip_pickle(NaT)
        assert p is NaT

        idx = pd.to_datetime(['2013-01-01', NaT, '2014-01-06'])
        idx_p = tm.round_trip_pickle(idx)
        assert idx_p[0] == idx[0]
        assert idx_p[1] is NaT
        assert idx_p[2] == idx[2]

        # GH11002
        # don't infer freq
        idx = date_range('1750-1-1', '2050-1-1', freq='7D')
        idx_p = tm.round_trip_pickle(idx)
        tm.assert_index_equal(idx, idx_p) 
Example #2
Source File: test_timeseries.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_pickle(self):

        # GH4606
        p = tm.round_trip_pickle(NaT)
        assert p is NaT

        idx = pd.to_datetime(['2013-01-01', NaT, '2014-01-06'])
        idx_p = tm.round_trip_pickle(idx)
        assert idx_p[0] == idx[0]
        assert idx_p[1] is NaT
        assert idx_p[2] == idx[2]

        # GH11002
        # don't infer freq
        idx = date_range('1750-1-1', '2050-1-1', freq='7D')
        idx_p = tm.round_trip_pickle(idx)
        tm.assert_index_equal(idx, idx_p) 
Example #3
Source File: test_subclass.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_dataframe_metadata(self):
        df = tm.SubclassedDataFrame({'X': [1, 2, 3], 'Y': [1, 2, 3]},
                                    index=['a', 'b', 'c'])
        df.testattr = 'XXX'

        assert df.testattr == 'XXX'
        assert df[['X']].testattr == 'XXX'
        assert df.loc[['a', 'b'], :].testattr == 'XXX'
        assert df.iloc[[0, 1], :].testattr == 'XXX'

        # see gh-9776
        assert df.iloc[0:1, :].testattr == 'XXX'

        # see gh-10553
        unpickled = tm.round_trip_pickle(df)
        tm.assert_frame_equal(df, unpickled)
        assert df._metadata == unpickled._metadata
        assert df.testattr == unpickled.testattr 
Example #4
Source File: test_timeseries.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_pickle(self):

        # GH4606
        p = tm.round_trip_pickle(NaT)
        assert p is NaT

        idx = pd.to_datetime(['2013-01-01', NaT, '2014-01-06'])
        idx_p = tm.round_trip_pickle(idx)
        assert idx_p[0] == idx[0]
        assert idx_p[1] is NaT
        assert idx_p[2] == idx[2]

        # GH11002
        # don't infer freq
        idx = date_range('1750-1-1', '2050-1-1', freq='7D')
        idx_p = tm.round_trip_pickle(idx)
        tm.assert_index_equal(idx, idx_p) 
Example #5
Source File: test_subclass.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_dataframe_metadata(self):
        df = tm.SubclassedDataFrame({'X': [1, 2, 3], 'Y': [1, 2, 3]},
                                    index=['a', 'b', 'c'])
        df.testattr = 'XXX'

        assert df.testattr == 'XXX'
        assert df[['X']].testattr == 'XXX'
        assert df.loc[['a', 'b'], :].testattr == 'XXX'
        assert df.iloc[[0, 1], :].testattr == 'XXX'

        # see gh-9776
        assert df.iloc[0:1, :].testattr == 'XXX'

        # see gh-10553
        unpickled = tm.round_trip_pickle(df)
        tm.assert_frame_equal(df, unpickled)
        assert df._metadata == unpickled._metadata
        assert df.testattr == unpickled.testattr 
Example #6
Source File: test_subclass.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_dataframe_metadata(self):
        df = tm.SubclassedDataFrame({'X': [1, 2, 3], 'Y': [1, 2, 3]},
                                    index=['a', 'b', 'c'])
        df.testattr = 'XXX'

        assert df.testattr == 'XXX'
        assert df[['X']].testattr == 'XXX'
        assert df.loc[['a', 'b'], :].testattr == 'XXX'
        assert df.iloc[[0, 1], :].testattr == 'XXX'

        # see gh-9776
        assert df.iloc[0:1, :].testattr == 'XXX'

        # see gh-10553
        unpickled = tm.round_trip_pickle(df)
        tm.assert_frame_equal(df, unpickled)
        assert df._metadata == unpickled._metadata
        assert df.testattr == unpickled.testattr 
Example #7
Source File: test_frame.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_pickle(self):

        def _test_roundtrip(frame, orig):
            result = tm.round_trip_pickle(frame)
            tm.assert_sp_frame_equal(frame, result)
            tm.assert_frame_equal(result.to_dense(), orig, check_dtype=False)

        _test_roundtrip(SparseDataFrame(), DataFrame())
        self._check_all(_test_roundtrip) 
Example #8
Source File: test_panel.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_pickle(self):
        with catch_warnings(record=True):
            unpickled = tm.round_trip_pickle(self.panel)
            assert_frame_equal(unpickled['ItemA'], self.panel['ItemA']) 
Example #9
Source File: test_period.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_round_trip(self):
        p = Period('2000Q1')
        new_p = tm.round_trip_pickle(p)
        assert new_p == p 
Example #10
Source File: test_timedelta.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self):

        v = Timedelta('1 days 10:11:12.0123456')
        v_p = tm.round_trip_pickle(v)
        assert v == v_p 
Example #11
Source File: test_series.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_pickle(self):
        def _test_roundtrip(series):
            unpickled = tm.round_trip_pickle(series)
            tm.assert_sp_series_equal(series, unpickled)
            tm.assert_series_equal(series.to_dense(), unpickled.to_dense())

        self._check_all(_test_roundtrip) 
Example #12
Source File: test_ops.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle_unpickle(self):
        unpickled = tm.round_trip_pickle(self.rng)
        assert unpickled.freq is not None 
Example #13
Source File: test_datetime.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_roundtrip_pickle_with_tz(self):

        # GH 8367
        # round-trip of timezone
        index = date_range('20130101', periods=3, tz='US/Eastern', name='foo')
        unpickled = tm.round_trip_pickle(index)
        tm.assert_index_equal(index, unpickled) 
Example #14
Source File: test_internals.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_pickle(self):
        def _check(blk):
            assert_block_equal(tm.round_trip_pickle(blk), blk)

        _check(self.fblock)
        _check(self.cblock)
        _check(self.oblock)
        _check(self.bool_block) 
Example #15
Source File: test_conversion.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_roundtrip_pickle_with_tz():
    return

    # GH 8367
    # round-trip of timezone
    index = MultiIndex.from_product(
        [[1, 2], ['a', 'b'], date_range('20130101', periods=3,
                                        tz='US/Eastern')
         ], names=['one', 'two', 'three'])
    unpickled = tm.round_trip_pickle(index)
    assert index.equal_levels(unpickled) 
Example #16
Source File: test_common.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self, indices):
        original_name, indices.name = indices.name, 'foo'
        unpickled = tm.round_trip_pickle(indices)
        assert indices.equals(unpickled)
        indices.name = original_name 
Example #17
Source File: test_internals.py    From elasticintel with GNU General Public License v3.0 5 votes vote down vote up
def test_non_unique_pickle(self):

        mgr = create_mgr('a,a,a:f8')
        mgr2 = tm.round_trip_pickle(mgr)
        assert_frame_equal(DataFrame(mgr), DataFrame(mgr2))

        mgr = create_mgr('a: f8; a: i8')
        mgr2 = tm.round_trip_pickle(mgr)
        assert_frame_equal(DataFrame(mgr), DataFrame(mgr2)) 
Example #18
Source File: test_timedelta.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self):

        rng = timedelta_range('1 days', periods=10)
        rng_p = tm.round_trip_pickle(rng)
        tm.assert_index_equal(rng, rng_p) 
Example #19
Source File: test_array.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self):
        def _check_roundtrip(obj):
            unpickled = tm.round_trip_pickle(obj)
            tm.assert_sp_array_equal(unpickled, obj)

        _check_roundtrip(self.arr)
        _check_roundtrip(self.zarr) 
Example #20
Source File: test_internals.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_categorical_block_pickle(self):
        mgr = create_mgr('a: category')
        mgr2 = tm.round_trip_pickle(mgr)
        assert_frame_equal(DataFrame(mgr), DataFrame(mgr2))

        smgr = create_single_mgr('category')
        smgr2 = tm.round_trip_pickle(smgr)
        assert_series_equal(Series(smgr), Series(smgr2)) 
Example #21
Source File: test_internals.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self, mgr):

        mgr2 = tm.round_trip_pickle(mgr)
        assert_frame_equal(DataFrame(mgr), DataFrame(mgr2))

        # share ref_items
        # assert mgr2.blocks[0].ref_items is mgr2.blocks[1].ref_items

        # GH2431
        assert hasattr(mgr2, "_is_consolidated")
        assert hasattr(mgr2, "_known_consolidated")

        # reset to False on load
        assert not mgr2._is_consolidated
        assert not mgr2._known_consolidated 
Example #22
Source File: test_internals.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self):
        def _check(blk):
            assert_block_equal(tm.round_trip_pickle(blk), blk)

        _check(self.fblock)
        _check(self.cblock)
        _check(self.oblock)
        _check(self.bool_block) 
Example #23
Source File: test_frame.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self, float_frame, float_frame_int_kind, float_frame_dense,
                    float_frame_fill0, float_frame_fill0_dense,
                    float_frame_fill2, float_frame_fill2_dense):

        def _test_roundtrip(frame, orig):
            result = tm.round_trip_pickle(frame)
            tm.assert_sp_frame_equal(frame, result)
            tm.assert_frame_equal(result.to_dense(), orig, check_dtype=False)

        _test_roundtrip(SparseDataFrame(), DataFrame())
        _test_roundtrip(float_frame, float_frame_dense)
        _test_roundtrip(float_frame_int_kind, float_frame_dense)
        _test_roundtrip(float_frame_fill0, float_frame_fill0_dense)
        _test_roundtrip(float_frame_fill2, float_frame_fill2_dense) 
Example #24
Source File: test_series.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self):
        def _test_roundtrip(series):
            unpickled = tm.round_trip_pickle(series)
            tm.assert_sp_series_equal(series, unpickled)
            tm.assert_series_equal(series.to_dense(), unpickled.to_dense())

        self._check_all(_test_roundtrip) 
Example #25
Source File: test_panel.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 5 votes vote down vote up
def test_pickle(self):
        unpickled = tm.round_trip_pickle(self.panel)
        assert_frame_equal(unpickled['ItemA'], self.panel['ItemA']) 
Example #26
Source File: test_period.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_round_trip(self):

        p = Period('2000Q1')
        new_p = tm.round_trip_pickle(p)
        assert new_p == p 
Example #27
Source File: test_timedelta.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_pickle(self):

        v = Timedelta('1 days 10:11:12.0123456')
        v_p = tm.round_trip_pickle(v)
        assert v == v_p 
Example #28
Source File: test_dtypes.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_caching(self):
        IntervalDtype.reset_cache()
        dtype = IntervalDtype("int64")
        assert len(IntervalDtype._cache) == 1

        IntervalDtype("interval")
        assert len(IntervalDtype._cache) == 2

        IntervalDtype.reset_cache()
        tm.round_trip_pickle(dtype)
        assert len(IntervalDtype._cache) == 0 
Example #29
Source File: test_dtypes.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_pickle(self):
        # make sure our cache is NOT pickled

        # clear the cache
        type(self.dtype).reset_cache()
        assert not len(self.dtype._cache)

        # force back to the cache
        result = tm.round_trip_pickle(self.dtype)
        assert result == self.dtype 
Example #30
Source File: test_block_internals.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_pickle(self):
        unpickled = tm.round_trip_pickle(self.mixed_frame)
        assert_frame_equal(self.mixed_frame, unpickled)

        # buglet
        self.mixed_frame._data.ndim

        # empty
        unpickled = tm.round_trip_pickle(self.empty)
        repr(unpickled)

        # tz frame
        unpickled = tm.round_trip_pickle(self.tzframe)
        assert_frame_equal(self.tzframe, unpickled)