Exemplo n.º 1
0
def test_pickle(indices):
    unpickled = tm.round_trip_pickle(indices)
    assert indices.equals(unpickled)
    original_name, indices.name = indices.name, 'foo'
    unpickled = tm.round_trip_pickle(indices)
    assert indices.equals(unpickled)
    indices.name = original_name
Exemplo n.º 2
0
    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))
Exemplo n.º 3
0
    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))
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    def test_pickle(self, float_string_frame, empty_frame, timezone_frame):
        unpickled = tm.round_trip_pickle(float_string_frame)
        assert_frame_equal(float_string_frame, unpickled)

        # buglet
        float_string_frame._data.ndim

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

        # tz frame
        unpickled = tm.round_trip_pickle(timezone_frame)
        assert_frame_equal(timezone_frame, unpickled)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 def test_timeseries_periodindex(self):
     # GH2891
     from pandas import period_range
     prng = period_range('1/1/2011', '1/1/2012', freq='M')
     ts = Series(np.random.randn(len(prng)), prng)
     new_ts = tm.round_trip_pickle(ts)
     assert new_ts.index.freq == 'M'
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
def test_roundtrip_pickle_with_tz():

    # 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)
Exemplo n.º 12
0
    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)

        # we are a singular object so we are added
        # back to the cache upon unpickling
        # this is to ensure object identity
        assert len(self.dtype._cache) == 1
        assert result == self.dtype
Exemplo n.º 13
0
    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
Exemplo n.º 14
0
    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
Exemplo n.º 15
0
    def test_dataframe_metadata(self):
        df = tm.SubclassedDataFrame({'X': [1, 2, 3], 'Y': [1, 2, 3]},
                                    index=['a', 'b', 'c'])
        df.testattr = 'XXX'

        self.assertEqual(df.testattr, 'XXX')
        self.assertEqual(df[['X']].testattr, 'XXX')
        self.assertEqual(df.loc[['a', 'b'], :].testattr, 'XXX')
        self.assertEqual(df.iloc[[0, 1], :].testattr, 'XXX')

        # GH9776
        self.assertEqual(df.iloc[0:1, :].testattr, 'XXX')

        # GH10553
        unpickled = tm.round_trip_pickle(df)
        tm.assert_frame_equal(df, unpickled)
        self.assertEqual(df._metadata, unpickled._metadata)
        self.assertEqual(df.testattr, unpickled.testattr)
Exemplo n.º 16
0
 def test_pickle_freq(self):
     # GH2891
     prng = period_range('1/1/2011', '1/1/2012', freq='M')
     new_prng = tm.round_trip_pickle(prng)
     self.assertEqual(new_prng.freq, offsets.MonthEnd())
     self.assertEqual(new_prng.freqstr, 'M')
Exemplo n.º 17
0
    def test_pickle(self):

        v = Timedelta('1 days 10:11:12.0123456')
        v_p = tm.round_trip_pickle(v)
        assert v == v_p
Exemplo n.º 18
0
 def _check(blk):
     assert_block_equal(tm.round_trip_pickle(blk), blk)
Exemplo n.º 19
0
 def test_pickle_round_trip(self, freq):
     idx = PeriodIndex(['2016-05-16', 'NaT', NaT, np.NaN], freq=freq)
     result = tm.round_trip_pickle(idx)
     tm.assert_index_equal(result, idx)
Exemplo n.º 20
0
 def test_pickle_unpickle(self):
     unpickled = tm.round_trip_pickle(self.rng)
     assert unpickled.offset is not None
Exemplo n.º 21
0
    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)
Exemplo n.º 22
0
    def test_round_trip(self):

        p = Period('2000Q1')
        new_p = tm.round_trip_pickle(p)
        assert new_p == p
Exemplo n.º 23
0
 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)
Exemplo n.º 24
0
 def verify_pickle(self, index):
     unpickled = tm.round_trip_pickle(index)
     assert index.equals(unpickled)
Exemplo n.º 25
0
    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)
Exemplo n.º 26
0
 def verify_pickle(self, indices):
     unpickled = tm.round_trip_pickle(indices)
     assert indices.equals(unpickled)
Exemplo n.º 27
0
 def test_pickle_freq(self):
     # GH2891
     prng = period_range('1/1/2011', '1/1/2012', freq='M')
     new_prng = tm.round_trip_pickle(prng)
     self.assertEqual(new_prng.freq, offsets.MonthEnd())
     self.assertEqual(new_prng.freqstr, 'M')
Exemplo n.º 28
0
 def _check_roundtrip(obj):
     unpickled = tm.round_trip_pickle(obj)
     tm.assert_sp_array_equal(unpickled, obj)
Exemplo n.º 29
0
 def _check(blk):
     assert_block_equal(tm.round_trip_pickle(blk), blk)
Exemplo n.º 30
0
 def test_pickle_freq(self):
     # GH2891
     prng = period_range('1/1/2011', '1/1/2012', freq='M')
     new_prng = tm.round_trip_pickle(prng)
     assert new_prng.freq == offsets.MonthEnd()
     assert new_prng.freqstr == 'M'
Exemplo n.º 31
0
 def test_pickle_freq(self):
     # GH2891
     prng = period_range('1/1/2011', '1/1/2012', freq='M')
     new_prng = tm.round_trip_pickle(prng)
     assert new_prng.freq == offsets.MonthEnd()
     assert new_prng.freqstr == 'M'
Exemplo n.º 32
0
    def test_pickle(self):

        v = Timedelta('1 days 10:11:12.0123456')
        v_p = tm.round_trip_pickle(v)
        assert v == v_p
Exemplo n.º 33
0
 def test_pickle_round_trip(self):
     for freq in ['D', 'M', 'A']:
         idx = PeriodIndex(['2016-05-16', 'NaT', NaT, np.NaN], freq=freq)
         result = tm.round_trip_pickle(idx)
         tm.assert_index_equal(result, idx)
Exemplo n.º 34
0
 def verify_pickle(self, indices):
     unpickled = tm.round_trip_pickle(indices)
     assert indices.equals(unpickled)
Exemplo n.º 35
0
 def test_pickle_round_trip(self):
     for freq in ['D', 'M', 'Y']:
         idx = PeriodIndex(['2016-05-16', 'NaT', NaT, np.NaN], freq='D')
         result = tm.round_trip_pickle(idx)
         tm.assert_index_equal(result, idx)
Exemplo n.º 36
0
    def test_pickle(self):

        v = Timedelta('1 days 10:11:12.0123456')
        v_p = tm.round_trip_pickle(v)
        self.assertEqual(v, v_p)
Exemplo n.º 37
0
 def test_pickle(self):
     result = tm.round_trip_pickle(self.dtype)
     self.assertEqual(result, self.dtype)