-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
CLN: datetimelike arrays: isort, small reorg #23587
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
Changes from 6 commits
e3267bc
d4bde65
a2754c1
e81f5d6
1647ea2
c99ca32
db1d446
1355f59
14d5e76
a0c7bf4
edab7a2
dd85053
e0c3fcf
6fe6496
469ac83
65209f1
0ada030
58dedcf
0a17757
4ac9576
c7211f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -272,10 +272,6 @@ def _concat_same_type(cls, to_concat): | |
|
||
# -------------------------------------------------------------------- | ||
# Data / Attributes | ||
@property | ||
def nbytes(self): | ||
# TODO(DatetimeArray): remove | ||
return self._data.nbytes | ||
|
||
@cache_readonly | ||
def dtype(self): | ||
|
@@ -286,10 +282,6 @@ def _ndarray_values(self): | |
# Ordinals | ||
return self._data | ||
|
||
@property | ||
def asi8(self): | ||
return self._data | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but for datetimes the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The inherited implementation returns |
||
|
||
@property | ||
def freq(self): | ||
"""Return the frequency object for this PeriodArray.""" | ||
|
@@ -330,13 +322,49 @@ def start_time(self): | |
def end_time(self): | ||
return self.to_timestamp(how='end') | ||
|
||
def __repr__(self): | ||
return '<{}>\n{}\nLength: {}, dtype: {}'.format( | ||
self.__class__.__name__, | ||
[str(s) for s in self], | ||
len(self), | ||
self.dtype | ||
) | ||
def to_timestamp(self, freq=None, how='start'): | ||
jreback marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Cast to DatetimeArray/Index | ||
jbrockmendel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Parameters | ||
---------- | ||
freq : string or DateOffset, optional | ||
Target frequency. The default is 'D' for week or longer, | ||
'S' otherwise | ||
how : {'s', 'e', 'start', 'end'} | ||
|
||
Returns | ||
------- | ||
DatetimeArray/Index | ||
""" | ||
from pandas.core.arrays import DatetimeArrayMixin | ||
|
||
how = libperiod._validate_end_alias(how) | ||
|
||
end = how == 'E' | ||
if end: | ||
if freq == 'B': | ||
# roll forward to ensure we land on B date | ||
adjust = Timedelta(1, 'D') - Timedelta(1, 'ns') | ||
return self.to_timestamp(how='start') + adjust | ||
else: | ||
adjust = Timedelta(1, 'ns') | ||
return (self + self.freq).to_timestamp(how='start') - adjust | ||
|
||
if freq is None: | ||
base, mult = frequencies.get_freq_code(self.freq) | ||
freq = frequencies.get_to_timestamp_base(base) | ||
else: | ||
freq = Period._maybe_convert_freq(freq) | ||
|
||
base, mult = frequencies.get_freq_code(freq) | ||
new_data = self.asfreq(freq, how=how) | ||
|
||
new_data = libperiod.periodarr_to_dt64arr(new_data.asi8, base) | ||
return DatetimeArrayMixin(new_data, freq='infer') | ||
|
||
# -------------------------------------------------------------------- | ||
# Array-like / EA-Interface Methods | ||
|
||
def __setitem__( | ||
self, | ||
|
@@ -456,6 +484,8 @@ def value_counts(self, dropna=False): | |
name=result.index.name) | ||
return Series(result.values, index=index, name=result.name) | ||
|
||
# -------------------------------------------------------------------- | ||
|
||
def shift(self, periods=1): | ||
""" | ||
Shift values by desired number. | ||
|
@@ -567,49 +597,9 @@ def asfreq(self, freq=None, how='E'): | |
|
||
return type(self)(new_data, freq=freq) | ||
|
||
def to_timestamp(self, freq=None, how='start'): | ||
""" | ||
Cast to DatetimeArray/Index | ||
|
||
Parameters | ||
---------- | ||
freq : string or DateOffset, optional | ||
Target frequency. The default is 'D' for week or longer, | ||
'S' otherwise | ||
how : {'s', 'e', 'start', 'end'} | ||
|
||
Returns | ||
------- | ||
DatetimeArray/Index | ||
""" | ||
from pandas.core.arrays import DatetimeArrayMixin | ||
|
||
how = libperiod._validate_end_alias(how) | ||
|
||
end = how == 'E' | ||
if end: | ||
if freq == 'B': | ||
# roll forward to ensure we land on B date | ||
adjust = Timedelta(1, 'D') - Timedelta(1, 'ns') | ||
return self.to_timestamp(how='start') + adjust | ||
else: | ||
adjust = Timedelta(1, 'ns') | ||
return (self + self.freq).to_timestamp(how='start') - adjust | ||
|
||
if freq is None: | ||
base, mult = frequencies.get_freq_code(self.freq) | ||
freq = frequencies.get_to_timestamp_base(base) | ||
else: | ||
freq = Period._maybe_convert_freq(freq) | ||
|
||
base, mult = frequencies.get_freq_code(freq) | ||
new_data = self.asfreq(freq, how=how) | ||
|
||
new_data = libperiod.periodarr_to_dt64arr(new_data.asi8, base) | ||
return DatetimeArrayMixin(new_data, freq='infer') | ||
|
||
# ------------------------------------------------------------------ | ||
# Formatting | ||
|
||
def _format_native_types(self, na_rep=u'NaT', date_format=None, **kwargs): | ||
""" actually format my specific types """ | ||
# TODO(DatetimeArray): remove | ||
|
@@ -630,9 +620,13 @@ def _format_native_types(self, na_rep=u'NaT', date_format=None, **kwargs): | |
values = np.array([formatter(dt) for dt in values]) | ||
return values | ||
|
||
# Delegation... | ||
def strftime(self, date_format): | ||
return self._format_native_types(date_format=date_format) | ||
|
||
def repeat(self, repeats, *args, **kwargs): | ||
""" | ||
Repeat elements of a Categorical. | ||
Repeat elements of a PeriodArray. | ||
|
||
See also | ||
-------- | ||
|
@@ -643,10 +637,6 @@ def repeat(self, repeats, *args, **kwargs): | |
values = self._data.repeat(repeats) | ||
return type(self)(values, self.freq) | ||
|
||
# Delegation... | ||
def strftime(self, date_format): | ||
return self._format_native_types(date_format=date_format) | ||
|
||
def astype(self, dtype, copy=True): | ||
# TODO: Figure out something better here... | ||
# We have DatetimeLikeArrayMixin -> | ||
|
Uh oh!
There was an error while loading. Please reload this page.