@@ -272,10 +272,6 @@ def _concat_same_type(cls, to_concat):
272
272
273
273
# --------------------------------------------------------------------
274
274
# Data / Attributes
275
- @property
276
- def nbytes (self ):
277
- # TODO(DatetimeArray): remove
278
- return self ._data .nbytes
279
275
280
276
@cache_readonly
281
277
def dtype (self ):
@@ -286,10 +282,6 @@ def _ndarray_values(self):
286
282
# Ordinals
287
283
return self ._data
288
284
289
- @property
290
- def asi8 (self ):
291
- return self ._data
292
-
293
285
@property
294
286
def freq (self ):
295
287
"""Return the frequency object for this PeriodArray."""
@@ -330,6 +322,50 @@ def start_time(self):
330
322
def end_time (self ):
331
323
return self .to_timestamp (how = 'end' )
332
324
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
+
333
369
def __repr__ (self ):
334
370
return '<{}>\n {}\n Length: {}, dtype: {}' .format (
335
371
self .__class__ .__name__ ,
@@ -456,6 +492,8 @@ def value_counts(self, dropna=False):
456
492
name = result .index .name )
457
493
return Series (result .values , index = index , name = result .name )
458
494
495
+ # --------------------------------------------------------------------
496
+
459
497
def shift (self , periods = 1 ):
460
498
"""
461
499
Shift values by desired number.
@@ -567,49 +605,9 @@ def asfreq(self, freq=None, how='E'):
567
605
568
606
return type (self )(new_data , freq = freq )
569
607
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
-
611
608
# ------------------------------------------------------------------
612
609
# Formatting
610
+
613
611
def _format_native_types (self , na_rep = u'NaT' , date_format = None , ** kwargs ):
614
612
""" actually format my specific types """
615
613
# TODO(DatetimeArray): remove
@@ -630,9 +628,13 @@ def _format_native_types(self, na_rep=u'NaT', date_format=None, **kwargs):
630
628
values = np .array ([formatter (dt ) for dt in values ])
631
629
return values
632
630
631
+ # Delegation...
632
+ def strftime (self , date_format ):
633
+ return self ._format_native_types (date_format = date_format )
634
+
633
635
def repeat (self , repeats , * args , ** kwargs ):
634
636
"""
635
- Repeat elements of a Categorical .
637
+ Repeat elements of a PeriodArray .
636
638
637
639
See also
638
640
--------
@@ -643,10 +645,6 @@ def repeat(self, repeats, *args, **kwargs):
643
645
values = self ._data .repeat (repeats )
644
646
return type (self )(values , self .freq )
645
647
646
- # Delegation...
647
- def strftime (self , date_format ):
648
- return self ._format_native_types (date_format = date_format )
649
-
650
648
def astype (self , dtype , copy = True ):
651
649
# TODO: Figure out something better here...
652
650
# We have DatetimeLikeArrayMixin ->
0 commit comments