def test_pickle(self, mgr): mgr2 = tm.round_trip_pickle(mgr) tm.assert_frame_equal(DataFrame(mgr), DataFrame(mgr2)) # 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_roundtrip_pickle_with_tz(): return # FIXME: this can't be right? # 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, mgr): mgr2 = tm.round_trip_pickle(mgr) tm.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_pickle(self, dtype): # make sure our cache is NOT pickled # clear the cache type(dtype).reset_cache() assert not len(dtype._cache) # force back to the cache result = tm.round_trip_pickle(dtype) if not isinstance(dtype, PeriodDtype): # Because PeriodDtype has a cython class as a base class, # it has different pickle semantics, and its cache is re-populated # on un-pickling. assert not len(dtype._cache) assert result == dtype
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_pickle_unpickle(self): unpickled = tm.round_trip_pickle(self.rng) assert unpickled.freq is not None
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_strings(string_series): unp_series = tm.round_trip_pickle(string_series) tm.assert_series_equal(unp_series, string_series)
def test_pickle(self, index): original_name, index.name = index.name, "foo" unpickled = tm.round_trip_pickle(index) assert index.equals(unpickled) index.name = original_name
def test_serializable(obj): # GH 35611 unpickled = tm.round_trip_pickle(obj) assert type(obj) == type(unpickled)
def test_pickle(self, typ, data): blk = create_block(typ, data) assert_block_equal(tm.round_trip_pickle(blk), blk)
def _check(blk): assert_block_equal(tm.round_trip_pickle(blk), blk)
def _check_roundtrip(obj): unpickled = tm.round_trip_pickle(obj) tm.assert_sp_array_equal(unpickled, obj)
def test_pickle_roundtrip_pandas(): result = tm.round_trip_pickle(pd.NA) assert result is pd.NA
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 _check_roundtrip(obj): unpickled = tm.round_trip_pickle(obj) assert unpickled == obj
def test_pickle(self, fix, request): obj = request.getfixturevalue(fix) unpickled = tm.round_trip_pickle(obj) tm.assert_sp_array_equal(unpickled, obj)
def test_pickle_after_set_freq(self): tdi = timedelta_range("1 day", periods=4, freq="s") tdi = tdi._with_freq(None) res = tm.round_trip_pickle(tdi) tm.assert_index_equal(res, tdi)
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_roundtrip_containers(as_frame, values, dtype): s = pd.Series(pd.array(values, dtype=dtype)) if as_frame: s = s.to_frame(name="A") result = tm.round_trip_pickle(s) tm.assert_equal(result, s)
def test_pickle_roundtrip(self, index): result = tm.round_trip_pickle(index) tm.assert_index_equal(result, index) if result.nlevels > 1: # GH#8367 round-trip with timezone assert index.equal_levels(result)
def test_pickle_round_trip_closed(self, closed): # https://github.com/pandas-dev/pandas/issues/35658 idx = IntervalIndex.from_tuples([(1, 2), (2, 3)], closed=closed) result = tm.round_trip_pickle(idx) tm.assert_index_equal(result, idx)
def _test_roundtrip(frame): unpickled = tm.round_trip_pickle(frame) tm.assert_frame_equal(frame, unpickled)
def test_non_unique_pickle(self, mgr_string): mgr = create_mgr(mgr_string) mgr2 = tm.round_trip_pickle(mgr) tm.assert_frame_equal(DataFrame(mgr), DataFrame(mgr2))
def test_pickle_timeseries_periodindex(): # GH#2891 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(): # GH#4606 p = tm.round_trip_pickle(NaT) assert p is NaT
def test_pickle_preserve_name(name): unpickled = tm.round_trip_pickle(tm.makeTimeSeries(name=name)) assert unpickled.name == name
def test_no_default_pickle(): # GH#40397 obj = tm.round_trip_pickle(lib.no_default) assert obj is lib.no_default
def test_pickle_datetimes(datetime_series): unp_ts = tm.round_trip_pickle(datetime_series) tm.assert_series_equal(unp_ts, datetime_series)