From 83f0b4fcb922df41398d2e2b21b1baa1dfa16625 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche <jorisvandenbossche@gmail.com> Date: Fri, 28 Sep 2018 19:55:17 +0200 Subject: [PATCH 1/2] CLN: remove Index._to_embed --- pandas/core/indexes/base.py | 14 +------------- pandas/core/indexes/datetimes.py | 17 ++++------------- pandas/core/indexes/period.py | 10 ---------- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b42bbdafcab45..af04a846ed787 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -1114,7 +1114,7 @@ def to_series(self, index=None, name=None): if name is None: name = self.name - return Series(self._to_embed(), index=index, name=name) + return Series(self.values.copy(), index=index, name=name) def to_frame(self, index=True, name=None): """ @@ -1177,18 +1177,6 @@ def to_frame(self, index=True, name=None): result.index = self return result - def _to_embed(self, keep_tz=False, dtype=None): - """ - *this is an internal non-public method* - - return an array repr of this object, potentially casting to object - - """ - if dtype is not None: - return self.astype(dtype)._to_embed(keep_tz=keep_tz) - - return self.values.copy() - _index_shared_docs['astype'] = """ Create an Index with values cast to dtypes. The class of a new Index is determined by dtype. When conversion is impossible, a ValueError diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index 9b00f21668bf5..e1628edbda83d 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -665,23 +665,14 @@ def to_series(self, keep_tz=False, index=None, name=None): if name is None: name = self.name - return Series(self._to_embed(keep_tz), index=index, name=name) - - def _to_embed(self, keep_tz=False, dtype=None): - """ - return an array repr of this object, potentially casting to object - - This is for internal compat - """ - if dtype is not None: - return self.astype(dtype)._to_embed(keep_tz=keep_tz) if keep_tz and self.tz is not None: - # preserve the tz & copy - return self.copy(deep=True) + values = self.copy(deep=True) + else: + values = self.values.copy() - return self.values.copy() + return Series(values, index=index, name=name) def to_period(self, freq=None): """ diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 0f86e18103e3c..969391569ce50 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -365,16 +365,6 @@ def __array_wrap__(self, result, context=None): # cannot pass _simple_new as it is return self._shallow_copy(result, freq=self.freq, name=self.name) - def _to_embed(self, keep_tz=False, dtype=None): - """ - return an array repr of this object, potentially casting to object - """ - - if dtype is not None: - return self.astype(dtype)._to_embed(keep_tz=keep_tz) - - return self.astype(object).values - @property def size(self): # Avoid materializing self._values From f7a0aaf978a1a0825e36212ca1a3edb33041a82b Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche <jorisvandenbossche@gmail.com> Date: Fri, 28 Sep 2018 21:00:27 +0200 Subject: [PATCH 2/2] pep8 --- pandas/core/indexes/datetimes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e1628edbda83d..a6cdaa0c2163a 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -665,7 +665,6 @@ def to_series(self, keep_tz=False, index=None, name=None): if name is None: name = self.name - if keep_tz and self.tz is not None: # preserve the tz & copy values = self.copy(deep=True)