Skip to content

Commit e487d48

Browse files
authored
CLN: share some more datetimelike index methods (#37865)
1 parent 971f4ff commit e487d48

File tree

6 files changed

+15
-31
lines changed

6 files changed

+15
-31
lines changed

pandas/core/arrays/datetimelike.py

+3
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,9 @@ def ceil(self, freq, ambiguous="raise", nonexistent="raise"):
15581558
# --------------------------------------------------------------
15591559
# Frequency Methods
15601560

1561+
def _maybe_clear_freq(self):
1562+
self._freq = None
1563+
15611564
def _with_freq(self, freq):
15621565
"""
15631566
Helper to get a view on the same data, with a new freq.

pandas/core/arrays/datetimes.py

-3
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,6 @@ def _check_compatible_with(self, other, setitem: bool = False):
476476
if not timezones.tz_compare(self.tz, other.tz):
477477
raise ValueError(f"Timezones don't match. '{self.tz}' != '{other.tz}'")
478478

479-
def _maybe_clear_freq(self):
480-
self._freq = None
481-
482479
# -----------------------------------------------------------------
483480
# Descriptive Properties
484481

pandas/core/arrays/timedeltas.py

-3
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,6 @@ def _check_compatible_with(self, other, setitem: bool = False):
313313
# we don't have anything to validate.
314314
pass
315315

316-
def _maybe_clear_freq(self):
317-
self._freq = None
318-
319316
# ----------------------------------------------------------------
320317
# Array-Like / EA-Interface Methods
321318

pandas/core/indexes/datetimelike.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ def _simple_new(
124124
def _is_all_dates(self) -> bool:
125125
return True
126126

127+
def _shallow_copy(self, values=None, name: Label = lib.no_default):
128+
name = self.name if name is lib.no_default else name
129+
130+
if values is not None:
131+
return self._simple_new(values, name=name)
132+
133+
result = self._simple_new(self._data, name=name)
134+
result._cache = self._cache
135+
return result
136+
127137
# ------------------------------------------------------------------------
128138
# Abstract data attributes
129139

@@ -682,16 +692,6 @@ def _with_freq(self, freq):
682692
arr = self._data._with_freq(freq)
683693
return type(self)._simple_new(arr, name=self.name)
684694

685-
def _shallow_copy(self, values=None, name: Label = lib.no_default):
686-
name = self.name if name is lib.no_default else name
687-
688-
if values is not None:
689-
return self._simple_new(values, name=name)
690-
691-
result = self._simple_new(self._data, name=name)
692-
result._cache = self._cache
693-
return result
694-
695695
# --------------------------------------------------------------------
696696
# Set Operation Methods
697697

pandas/core/indexes/period.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55

66
from pandas._libs import index as libindex
7-
from pandas._libs.lib import no_default
87
from pandas._libs.tslibs import BaseOffset, Period, Resolution, Tick
98
from pandas._libs.tslibs.parsing import DateParseError, parse_time_string
109
from pandas._typing import DtypeObj, Label
@@ -257,16 +256,6 @@ def _has_complex_internals(self) -> bool:
257256
# used to avoid libreduction code paths, which raise or require conversion
258257
return True
259258

260-
def _shallow_copy(self, values=None, name: Label = no_default):
261-
name = name if name is not no_default else self.name
262-
263-
if values is not None:
264-
return self._simple_new(values, name=name)
265-
266-
result = self._simple_new(self._data, name=name)
267-
result._cache = self._cache
268-
return result
269-
270259
def _maybe_convert_timedelta(self, other):
271260
"""
272261
Convert timedelta-like input to an integer multiple of self.freq
@@ -320,7 +309,7 @@ def _mpl_repr(self):
320309

321310
@property
322311
def _formatter_func(self):
323-
return self.array._formatter(boxed=False)
312+
return self._data._formatter(boxed=False)
324313

325314
# ------------------------------------------------------------------------
326315
# Indexing

pandas/core/indexes/timedeltas.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ def __new__(
162162

163163
@property
164164
def _formatter_func(self):
165-
from pandas.io.formats.format import get_format_timedelta64
166-
167-
return get_format_timedelta64(self, box=True)
165+
return self._data._formatter()
168166

169167
# -------------------------------------------------------------------
170168

0 commit comments

Comments
 (0)