@@ -272,10 +272,6 @@ def _concat_same_type(cls, to_concat):
272272
273273 # --------------------------------------------------------------------
274274 # Data / Attributes
275- @property
276- def nbytes (self ):
277- # TODO(DatetimeArray): remove
278- return self ._data .nbytes
279275
280276 @cache_readonly
281277 def dtype (self ):
@@ -286,10 +282,6 @@ def _ndarray_values(self):
286282 # Ordinals
287283 return self ._data
288284
289- @property
290- def asi8 (self ):
291- return self ._data
292-
293285 @property
294286 def freq (self ):
295287 """Return the frequency object for this PeriodArray."""
@@ -330,6 +322,50 @@ def start_time(self):
330322 def end_time (self ):
331323 return self .to_timestamp (how = 'end' )
332324
325+ def to_timestamp (self , freq = None , how = 'start' ):
326+ """
327+ Cast to DatetimeArray/Index.
328+
329+ Parameters
330+ ----------
331+ freq : string or DateOffset, optional
332+ Target frequency. The default is 'D' for week or longer,
333+ 'S' otherwise
334+ how : {'s', 'e', 'start', 'end'}
335+
336+ Returns
337+ -------
338+ DatetimeArray/Index
339+ """
340+ from pandas .core .arrays import DatetimeArrayMixin
341+
342+ how = libperiod ._validate_end_alias (how )
343+
344+ end = how == 'E'
345+ if end :
346+ if freq == 'B' :
347+ # roll forward to ensure we land on B date
348+ adjust = Timedelta (1 , 'D' ) - Timedelta (1 , 'ns' )
349+ return self .to_timestamp (how = 'start' ) + adjust
350+ else :
351+ adjust = Timedelta (1 , 'ns' )
352+ return (self + self .freq ).to_timestamp (how = 'start' ) - adjust
353+
354+ if freq is None :
355+ base , mult = frequencies .get_freq_code (self .freq )
356+ freq = frequencies .get_to_timestamp_base (base )
357+ else :
358+ freq = Period ._maybe_convert_freq (freq )
359+
360+ base , mult = frequencies .get_freq_code (freq )
361+ new_data = self .asfreq (freq , how = how )
362+
363+ new_data = libperiod .periodarr_to_dt64arr (new_data .asi8 , base )
364+ return DatetimeArrayMixin (new_data , freq = 'infer' )
365+
366+ # --------------------------------------------------------------------
367+ # Array-like / EA-Interface Methods
368+
333369 def __repr__ (self ):
334370 return '<{}>\n {}\n Length: {}, dtype: {}' .format (
335371 self .__class__ .__name__ ,
@@ -456,6 +492,8 @@ def value_counts(self, dropna=False):
456492 name = result .index .name )
457493 return Series (result .values , index = index , name = result .name )
458494
495+ # --------------------------------------------------------------------
496+
459497 def shift (self , periods = 1 ):
460498 """
461499 Shift values by desired number.
@@ -567,49 +605,9 @@ def asfreq(self, freq=None, how='E'):
567605
568606 return type (self )(new_data , freq = freq )
569607
570- def to_timestamp (self , freq = None , how = 'start' ):
571- """
572- Cast to DatetimeArray/Index
573-
574- Parameters
575- ----------
576- freq : string or DateOffset, optional
577- Target frequency. The default is 'D' for week or longer,
578- 'S' otherwise
579- how : {'s', 'e', 'start', 'end'}
580-
581- Returns
582- -------
583- DatetimeArray/Index
584- """
585- from pandas .core .arrays import DatetimeArrayMixin
586-
587- how = libperiod ._validate_end_alias (how )
588-
589- end = how == 'E'
590- if end :
591- if freq == 'B' :
592- # roll forward to ensure we land on B date
593- adjust = Timedelta (1 , 'D' ) - Timedelta (1 , 'ns' )
594- return self .to_timestamp (how = 'start' ) + adjust
595- else :
596- adjust = Timedelta (1 , 'ns' )
597- return (self + self .freq ).to_timestamp (how = 'start' ) - adjust
598-
599- if freq is None :
600- base , mult = frequencies .get_freq_code (self .freq )
601- freq = frequencies .get_to_timestamp_base (base )
602- else :
603- freq = Period ._maybe_convert_freq (freq )
604-
605- base , mult = frequencies .get_freq_code (freq )
606- new_data = self .asfreq (freq , how = how )
607-
608- new_data = libperiod .periodarr_to_dt64arr (new_data .asi8 , base )
609- return DatetimeArrayMixin (new_data , freq = 'infer' )
610-
611608 # ------------------------------------------------------------------
612609 # Formatting
610+
613611 def _format_native_types (self , na_rep = u'NaT' , date_format = None , ** kwargs ):
614612 """ actually format my specific types """
615613 # TODO(DatetimeArray): remove
@@ -630,9 +628,13 @@ def _format_native_types(self, na_rep=u'NaT', date_format=None, **kwargs):
630628 values = np .array ([formatter (dt ) for dt in values ])
631629 return values
632630
631+ # Delegation...
632+ def strftime (self , date_format ):
633+ return self ._format_native_types (date_format = date_format )
634+
633635 def repeat (self , repeats , * args , ** kwargs ):
634636 """
635- Repeat elements of a Categorical .
637+ Repeat elements of a PeriodArray .
636638
637639 See also
638640 --------
@@ -643,10 +645,6 @@ def repeat(self, repeats, *args, **kwargs):
643645 values = self ._data .repeat (repeats )
644646 return type (self )(values , self .freq )
645647
646- # Delegation...
647- def strftime (self , date_format ):
648- return self ._format_native_types (date_format = date_format )
649-
650648 def astype (self , dtype , copy = True ):
651649 # TODO: Figure out something better here...
652650 # We have DatetimeLikeArrayMixin ->
0 commit comments