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
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))
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))
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
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)
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)
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)
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'
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)
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
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)
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
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
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
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)
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')
def test_pickle(self): v = Timedelta('1 days 10:11:12.0123456') v_p = tm.round_trip_pickle(v) assert v == v_p
def _check(blk): assert_block_equal(tm.round_trip_pickle(blk), blk)
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)
def test_pickle_unpickle(self): unpickled = tm.round_trip_pickle(self.rng) assert unpickled.offset is not None
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)
def test_round_trip(self): p = Period('2000Q1') new_p = tm.round_trip_pickle(p) assert new_p == p
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)
def verify_pickle(self, index): unpickled = tm.round_trip_pickle(index) assert index.equals(unpickled)
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)
def verify_pickle(self, indices): unpickled = tm.round_trip_pickle(indices) assert indices.equals(unpickled)
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')
def _check_roundtrip(obj): unpickled = tm.round_trip_pickle(obj) tm.assert_sp_array_equal(unpickled, obj)
def _check(blk): assert_block_equal(tm.round_trip_pickle(blk), blk)
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'
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'
def test_pickle(self): v = Timedelta('1 days 10:11:12.0123456') v_p = tm.round_trip_pickle(v) assert v == v_p
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)
def verify_pickle(self, indices): unpickled = tm.round_trip_pickle(indices) assert indices.equals(unpickled)
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)
def test_pickle(self): v = Timedelta('1 days 10:11:12.0123456') v_p = tm.round_trip_pickle(v) self.assertEqual(v, v_p)
def test_pickle(self): result = tm.round_trip_pickle(self.dtype) self.assertEqual(result, self.dtype)