Skip to content

CLN: share some more datetimelike index methods #37865

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
Nov 18, 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
3 changes: 3 additions & 0 deletions pandas/core/arrays/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,9 @@ def ceil(self, freq, ambiguous="raise", nonexistent="raise"):
# --------------------------------------------------------------
# Frequency Methods

def _maybe_clear_freq(self):
self._freq = None

def _with_freq(self, freq):
"""
Helper to get a view on the same data, with a new freq.
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/arrays/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,6 @@ def _check_compatible_with(self, other, setitem: bool = False):
if not timezones.tz_compare(self.tz, other.tz):
raise ValueError(f"Timezones don't match. '{self.tz}' != '{other.tz}'")

def _maybe_clear_freq(self):
self._freq = None

# -----------------------------------------------------------------
# Descriptive Properties

Expand Down
3 changes: 0 additions & 3 deletions pandas/core/arrays/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,6 @@ def _check_compatible_with(self, other, setitem: bool = False):
# we don't have anything to validate.
pass

def _maybe_clear_freq(self):
self._freq = None

# ----------------------------------------------------------------
# Array-Like / EA-Interface Methods

Expand Down
20 changes: 10 additions & 10 deletions pandas/core/indexes/datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ class DatetimeIndexOpsMixin(NDArrayBackedExtensionIndex):
def _is_all_dates(self) -> bool:
return True

def _shallow_copy(self, values=None, name: Label = lib.no_default):
name = self.name if name is lib.no_default else name

if values is not None:
return self._simple_new(values, name=name)

result = self._simple_new(self._data, name=name)
result._cache = self._cache
return result

# ------------------------------------------------------------------------
# Abstract data attributes

Expand Down Expand Up @@ -662,16 +672,6 @@ def _with_freq(self, freq):
arr = self._data._with_freq(freq)
return type(self)._simple_new(arr, name=self.name)

def _shallow_copy(self, values=None, name: Label = lib.no_default):
name = self.name if name is lib.no_default else name

if values is not None:
return self._simple_new(values, name=name)

result = self._simple_new(self._data, name=name)
result._cache = self._cache
return result

# --------------------------------------------------------------------
# Set Operation Methods

Expand Down
13 changes: 1 addition & 12 deletions pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np

from pandas._libs import index as libindex
from pandas._libs.lib import no_default
from pandas._libs.tslibs import BaseOffset, Period, Resolution, Tick
from pandas._libs.tslibs.parsing import DateParseError, parse_time_string
from pandas._typing import DtypeObj, Label
Expand Down Expand Up @@ -278,16 +277,6 @@ def _has_complex_internals(self) -> bool:
# used to avoid libreduction code paths, which raise or require conversion
return True

def _shallow_copy(self, values=None, name: Label = no_default):
name = name if name is not no_default else self.name

if values is not None:
return self._simple_new(values, name=name)

result = self._simple_new(self._data, name=name)
result._cache = self._cache
return result

def _maybe_convert_timedelta(self, other):
"""
Convert timedelta-like input to an integer multiple of self.freq
Expand Down Expand Up @@ -341,7 +330,7 @@ def _mpl_repr(self):

@property
def _formatter_func(self):
return self.array._formatter(boxed=False)
return self._data._formatter(boxed=False)

# ------------------------------------------------------------------------
# Indexing
Expand Down
4 changes: 1 addition & 3 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ def _simple_new(cls, values: TimedeltaArray, name: Label = None):

@property
def _formatter_func(self):
from pandas.io.formats.format import get_format_timedelta64

return get_format_timedelta64(self, box=True)
return self._data._formatter()

# -------------------------------------------------------------------

Expand Down