From 3ac23393b36d264de18fd19543cd93d24520c2ee Mon Sep 17 00:00:00 2001 From: Brock Mendel Date: Tue, 7 Jan 2020 17:24:43 -0800 Subject: [PATCH] CLN: remove Index __setstate__ methods --- pandas/core/indexes/base.py | 29 ------------------------- pandas/core/indexes/datetimes.py | 35 ------------------------------- pandas/core/indexes/period.py | 30 -------------------------- pandas/core/indexes/timedeltas.py | 11 ---------- 4 files changed, 105 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 087db014de5b3..732eba804d469 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1726,35 +1726,6 @@ def __reduce__(self): d.update(self._get_attributes_dict()) return _new_Index, (type(self), d), None - def __setstate__(self, state): - """ - Necessary for making this object picklable. - """ - - if isinstance(state, dict): - self._data = state.pop("data") - for k, v in state.items(): - setattr(self, k, v) - - elif isinstance(state, tuple): - - if len(state) == 2: - nd_state, own_state = state - data = np.empty(nd_state[1], dtype=nd_state[2]) - np.ndarray.__setstate__(data, nd_state) - self._name = own_state[0] - - else: # pragma: no cover - data = np.empty(state) - np.ndarray.__setstate__(data, state) - - self._data = data - self._reset_identity() - else: - raise Exception("invalid pickle state") - - _unpickle_compat = __setstate__ - # -------------------------------------------------------------------- # Null Handling Methods diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 88b841e7d4a88..9db30ce710c0d 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -319,41 +319,6 @@ def __reduce__(self): d.update(self._get_attributes_dict()) return _new_DatetimeIndex, (type(self), d), None - def __setstate__(self, state): - """ - Necessary for making this object picklable. - """ - if isinstance(state, dict): - super().__setstate__(state) - - elif isinstance(state, tuple): - - # < 0.15 compat - if len(state) == 2: - nd_state, own_state = state - data = np.empty(nd_state[1], dtype=nd_state[2]) - np.ndarray.__setstate__(data, nd_state) - - freq = own_state[1] - tz = timezones.tz_standardize(own_state[2]) - dtype = tz_to_dtype(tz) - dtarr = DatetimeArray._simple_new(data, freq=freq, dtype=dtype) - - self.name = own_state[0] - - else: # pragma: no cover - data = np.empty(state) - np.ndarray.__setstate__(data, state) - dtarr = DatetimeArray(data) - - self._data = dtarr - self._reset_identity() - - else: - raise Exception("invalid pickle state") - - _unpickle_compat = __setstate__ - def _convert_for_op(self, value): """ Convert value to be insertable to ndarray. diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 1fed0201f7b2b..c3832e0bac2d6 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -826,36 +826,6 @@ def _apply_meta(self, rawarr): rawarr = PeriodIndex._simple_new(rawarr, freq=self.freq, name=self.name) return rawarr - def __setstate__(self, state): - """Necessary for making this object picklable""" - - if isinstance(state, dict): - super().__setstate__(state) - - elif isinstance(state, tuple): - - # < 0.15 compat - if len(state) == 2: - nd_state, own_state = state - data = np.empty(nd_state[1], dtype=nd_state[2]) - np.ndarray.__setstate__(data, nd_state) - - # backcompat - freq = Period._maybe_convert_freq(own_state[1]) - - else: # pragma: no cover - data = np.empty(state) - np.ndarray.__setstate__(self, state) - freq = None # ? - - data = PeriodArray(data, freq=freq) - self._data = data - - else: - raise Exception("invalid pickle state") - - _unpickle_compat = __setstate__ - def memory_usage(self, deep=False): result = super().memory_usage(deep=deep) if hasattr(self, "_cache") and "_int64index" in self._cache: diff --git a/pandas/core/indexes/timedeltas.py b/pandas/core/indexes/timedeltas.py index 59fc53a17590c..d1d8db0746cf8 100644 --- a/pandas/core/indexes/timedeltas.py +++ b/pandas/core/indexes/timedeltas.py @@ -202,17 +202,6 @@ def _simple_new(cls, values, name=None, freq=None, dtype=_TD_DTYPE): result._reset_identity() return result - # ------------------------------------------------------------------- - - def __setstate__(self, state): - """Necessary for making this object picklable""" - if isinstance(state, dict): - super().__setstate__(state) - else: - raise Exception("invalid pickle state") - - _unpickle_compat = __setstate__ - # ------------------------------------------------------------------- # Rendering Methods