Skip to content

CLN: remove Index __setstate__ methods #30807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 0 additions & 35 deletions pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 0 additions & 30 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 0 additions & 11 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down