|
1 | 1 | from datetime import datetime
|
2 | 2 | import numpy as np
|
3 | 3 |
|
4 |
| -from pandas.tseries.frequencies import get_freq_code as _gfc |
| 4 | +from pandas.tseries.frequencies import get_freq_code as _gfc, to_offset |
5 | 5 | from pandas.tseries.index import DatetimeIndex, Int64Index
|
6 | 6 | from pandas.tseries.tools import parse_time_string
|
7 | 7 | import pandas.tseries.frequencies as _freq_mod
|
8 | 8 |
|
9 | 9 | import pandas.core.common as com
|
10 |
| -import pandas.core.datetools as datetools |
11 | 10 | from pandas.util import py3compat
|
12 | 11 |
|
13 | 12 | from pandas._tseries import Timestamp
|
@@ -190,31 +189,37 @@ def asfreq(self, freq=None, how='E'):
|
190 | 189 |
|
191 | 190 | return Period(new_ordinal, (base2, mult2))
|
192 | 191 |
|
| 192 | + @property |
193 | 193 | def start_time(self):
|
194 |
| - return self.to_timestamp(which_end='S') |
| 194 | + return self.to_timestamp(how='S') |
195 | 195 |
|
| 196 | + @property |
196 | 197 | def end_time(self):
|
197 |
| - return self.to_timestamp(which_end='E') |
| 198 | + return self.to_timestamp(how='E') |
198 | 199 |
|
199 |
| - def to_timestamp(self, which_end='S'): |
| 200 | + def to_timestamp(self, freq='D', how='S'): |
200 | 201 | """
|
201 | 202 | Return the Timestamp at the start/end of the period
|
202 | 203 |
|
203 | 204 | Parameters
|
204 | 205 | ----------
|
205 |
| - which_end: str, default 'S' (start) |
| 206 | + freq : string or DateOffset, default 'D' |
| 207 | + Target frequency |
| 208 | + how: str, default 'S' (start) |
206 | 209 | 'S', 'E'. Can be aliased as case insensitive
|
207 | 210 | 'Start', 'Finish', 'Begin', 'End'
|
208 | 211 |
|
209 | 212 | Returns
|
210 | 213 | -------
|
211 | 214 | Timestamp
|
212 | 215 | """
|
213 |
| - which_end = _validate_end_alias(which_end) |
214 |
| - new_val = self.asfreq('S', which_end) |
215 |
| - base, mult = _gfc(new_val.freq) |
216 |
| - return Timestamp(lib.period_ordinal_to_dt64(new_val.ordinal, base, |
217 |
| - mult)) |
| 216 | + # how = _validate_end_alias(how) |
| 217 | + |
| 218 | + base, mult = _gfc(freq) |
| 219 | + new_val = self.asfreq(freq, how) |
| 220 | + new_val = lib.period_ordinal_to_dt64(new_val.ordinal, base, mult) |
| 221 | + ts_freq = _period_rule_to_timestamp_rule(self.freq, how=how) |
| 222 | + return Timestamp(new_val, offset=to_offset(ts_freq)) |
218 | 223 |
|
219 | 224 | year = _period_field_accessor('year')
|
220 | 225 | month = _period_field_accessor('month')
|
@@ -474,7 +479,7 @@ def __new__(cls, data=None,
|
474 | 479 | if isinstance(freq, Period):
|
475 | 480 | freq = freq.freq
|
476 | 481 | else:
|
477 |
| - freq = datetools.get_standard_freq(freq) |
| 482 | + freq = _freq_mod.get_standard_freq(freq) |
478 | 483 |
|
479 | 484 | if data is None:
|
480 | 485 | subarr, freq = _get_ordinal_range(start, end, periods, freq)
|
@@ -587,14 +592,16 @@ def map(self, func_to_map):
|
587 | 592 |
|
588 | 593 | def _mpl_repr(self):
|
589 | 594 | # how to represent ourselves to matplotlib
|
590 |
| - return datetools._period_box_array(self, self.freq) |
| 595 | + return _period_box_array(self, self.freq) |
591 | 596 |
|
592 | 597 | def to_timestamp(self, freq='D', how='start'):
|
593 | 598 | """
|
594 |
| - Cast to datetimeindex of timestamps, at *beginning* of period |
| 599 | + Cast to DatetimeIndex |
595 | 600 |
|
596 | 601 | Parameters
|
597 | 602 | ----------
|
| 603 | + freq : string or DateOffset, default 'D' |
| 604 | + Target frequency |
598 | 605 | how : {'s', 'e', 'start', 'end'}
|
599 | 606 |
|
600 | 607 | Returns
|
@@ -657,7 +664,7 @@ def get_value(self, series, key):
|
657 | 664 | return super(PeriodIndex, self).get_value(series, key)
|
658 | 665 | except KeyError:
|
659 | 666 | try:
|
660 |
| - asdt, parsed, reso = datetools.parse_time_string(key) |
| 667 | + asdt, parsed, reso = parse_time_string(key) |
661 | 668 | grp = _freq_mod._infer_period_group(reso)
|
662 | 669 | freqn = _freq_mod._period_group(self.freq)
|
663 | 670 |
|
@@ -695,7 +702,7 @@ def get_loc(self, key):
|
695 | 702 | return self._engine.get_loc(key)
|
696 | 703 | except KeyError:
|
697 | 704 | try:
|
698 |
| - asdt, parsed, reso = datetools.parse_time_string(key) |
| 705 | + asdt, parsed, reso = parse_time_string(key) |
699 | 706 | key = asdt
|
700 | 707 | except TypeError:
|
701 | 708 | pass
|
|
0 commit comments