CLN: remove Index._to_embed (#22879) · TomAugspurger/pandas@1d9f76c (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -1114,7 +1114,7 @@ def to_series(self, index=None, name=None):
1114 1114 if name is None:
1115 1115 name = self.name
1116 1116
1117 -return Series(self._to_embed(), index=index, name=name)
1117 +return Series(self.values.copy(), index=index, name=name)
1118 1118
1119 1119 def to_frame(self, index=True, name=None):
1120 1120 """
@@ -1177,18 +1177,6 @@ def to_frame(self, index=True, name=None):
1177 1177 result.index = self
1178 1178 return result
1179 1179
1180 -def _to_embed(self, keep_tz=False, dtype=None):
1181 -"""
1182 - *this is an internal non-public method*
1183 -
1184 - return an array repr of this object, potentially casting to object
1185 -
1186 - """
1187 -if dtype is not None:
1188 -return self.astype(dtype)._to_embed(keep_tz=keep_tz)
1189 -
1190 -return self.values.copy()
1191 -
1192 1180 _index_shared_docs['astype'] = """
1193 1181 Create an Index with values cast to dtypes. The class of a new Index
1194 1182 is determined by dtype. When conversion is impossible, a ValueError
Original file line number Diff line number Diff line change
@@ -665,23 +665,13 @@ def to_series(self, keep_tz=False, index=None, name=None):
665 665 if name is None:
666 666 name = self.name
667 667
668 -return Series(self._to_embed(keep_tz), index=index, name=name)
669 -
670 -def _to_embed(self, keep_tz=False, dtype=None):
671 -"""
672 - return an array repr of this object, potentially casting to object
673 -
674 - This is for internal compat
675 - """
676 -if dtype is not None:
677 -return self.astype(dtype)._to_embed(keep_tz=keep_tz)
678 -
679 668 if keep_tz and self.tz is not None:
680 -
681 669 # preserve the tz & copy
682 -return self.copy(deep=True)
670 +values = self.copy(deep=True)
671 +else:
672 +values = self.values.copy()
683 673
684 -return self.values.copy()
674 +return Series(values, index=index, name=name)
685 675
686 676 def to_period(self, freq=None):
687 677 """
Original file line number Diff line number Diff line change
@@ -365,16 +365,6 @@ def __array_wrap__(self, result, context=None):
365 365 # cannot pass _simple_new as it is
366 366 return self._shallow_copy(result, freq=self.freq, name=self.name)
367 367
368 -def _to_embed(self, keep_tz=False, dtype=None):
369 -"""
370 - return an array repr of this object, potentially casting to object
371 - """
372 -
373 -if dtype is not None:
374 -return self.astype(dtype)._to_embed(keep_tz=keep_tz)
375 -
376 -return self.astype(object).values
377 -
378 368 @property
379 369 def size(self):
380 370 # Avoid materializing self._values