31
31
pandas_dtype ,
32
32
)
33
33
from pandas .core .dtypes .dtypes import PeriodDtype
34
- from pandas .core .dtypes .generic import (
35
- ABCIndexClass ,
36
- ABCPeriod ,
37
- ABCPeriodArray ,
38
- ABCPeriodIndex ,
39
- ABCSeries ,
40
- )
34
+ from pandas .core .dtypes .generic import ABCIndexClass , ABCPeriodIndex , ABCSeries
41
35
from pandas .core .dtypes .missing import isna , notna
42
36
43
37
import pandas .core .algorithms as algos
48
42
from pandas .tseries .offsets import DateOffset , Tick , _delta_to_tick
49
43
50
44
51
- def _field_accessor (name , alias , docstring = None ):
45
+ def _field_accessor (name : str , alias : int , docstring = None ):
52
46
def f (self ):
53
47
base , mult = libfrequencies .get_freq_code (self .freq )
54
48
result = get_period_field_arr (alias , self .asi8 , base )
@@ -170,7 +164,7 @@ def __init__(self, values, freq=None, dtype=None, copy=False):
170
164
self ._dtype = PeriodDtype (freq )
171
165
172
166
@classmethod
173
- def _simple_new (cls , values : np .ndarray , freq = None , ** kwargs ):
167
+ def _simple_new (cls , values : np .ndarray , freq = None , ** kwargs ) -> "PeriodArray" :
174
168
# alias for PeriodArray.__init__
175
169
assert isinstance (values , np .ndarray ) and values .dtype == "i8"
176
170
return cls (values , freq = freq , ** kwargs )
@@ -181,7 +175,7 @@ def _from_sequence(
181
175
scalars : Sequence [Optional [Period ]],
182
176
dtype : Optional [PeriodDtype ] = None ,
183
177
copy : bool = False ,
184
- ) -> ABCPeriodArray :
178
+ ) -> "PeriodArray" :
185
179
if dtype :
186
180
freq = dtype .freq
187
181
else :
@@ -202,11 +196,13 @@ def _from_sequence(
202
196
return cls (ordinals , freq = freq )
203
197
204
198
@classmethod
205
- def _from_sequence_of_strings (cls , strings , dtype = None , copy = False ):
199
+ def _from_sequence_of_strings (
200
+ cls , strings , dtype = None , copy = False
201
+ ) -> "PeriodArray" :
206
202
return cls ._from_sequence (strings , dtype , copy )
207
203
208
204
@classmethod
209
- def _from_datetime64 (cls , data , freq , tz = None ):
205
+ def _from_datetime64 (cls , data , freq , tz = None ) -> "PeriodArray" :
210
206
"""
211
207
Construct a PeriodArray from a datetime64 array
212
208
@@ -270,12 +266,12 @@ def _check_compatible_with(self, other, setitem: bool = False):
270
266
# Data / Attributes
271
267
272
268
@cache_readonly
273
- def dtype (self ):
269
+ def dtype (self ) -> PeriodDtype :
274
270
return self ._dtype
275
271
276
272
# error: Read-only property cannot override read-write property [misc]
277
273
@property # type: ignore
278
- def freq (self ):
274
+ def freq (self ) -> DateOffset :
279
275
"""
280
276
Return the frequency object for this PeriodArray.
281
277
"""
@@ -402,7 +398,7 @@ def __arrow_array__(self, type=None):
402
398
daysinmonth = days_in_month
403
399
404
400
@property
405
- def is_leap_year (self ):
401
+ def is_leap_year (self ) -> np . ndarray :
406
402
"""
407
403
Logical indicating if the date belongs to a leap year.
408
404
"""
@@ -458,12 +454,6 @@ def to_timestamp(self, freq=None, how="start"):
458
454
new_data = libperiod .periodarr_to_dt64arr (new_data .asi8 , base )
459
455
return DatetimeArray ._from_sequence (new_data , freq = "infer" )
460
456
461
- # --------------------------------------------------------------------
462
- # Array-like / EA-Interface Methods
463
-
464
- def _values_for_argsort (self ):
465
- return self ._data
466
-
467
457
# --------------------------------------------------------------------
468
458
469
459
def _time_shift (self , periods , freq = None ):
@@ -495,7 +485,7 @@ def _time_shift(self, periods, freq=None):
495
485
def _box_func (self ):
496
486
return lambda x : Period ._from_ordinal (ordinal = x , freq = self .freq )
497
487
498
- def asfreq (self , freq = None , how = "E" ):
488
+ def asfreq (self , freq = None , how = "E" ) -> "PeriodArray" :
499
489
"""
500
490
Convert the Period Array/Index to the specified frequency `freq`.
501
491
@@ -557,7 +547,7 @@ def asfreq(self, freq=None, how="E"):
557
547
# ------------------------------------------------------------------
558
548
# Rendering Methods
559
549
560
- def _formatter (self , boxed = False ):
550
+ def _formatter (self , boxed : bool = False ):
561
551
if boxed :
562
552
return str
563
553
return "'{}'" .format
@@ -584,7 +574,7 @@ def _format_native_types(self, na_rep="NaT", date_format=None, **kwargs):
584
574
585
575
# ------------------------------------------------------------------
586
576
587
- def astype (self , dtype , copy = True ):
577
+ def astype (self , dtype , copy : bool = True ):
588
578
# We handle Period[T] -> Period[U]
589
579
# Our parent handles everything else.
590
580
dtype = pandas_dtype (dtype )
@@ -965,8 +955,8 @@ def _get_ordinal_range(start, end, periods, freq, mult=1):
965
955
if end is not None :
966
956
end = Period (end , freq )
967
957
968
- is_start_per = isinstance (start , ABCPeriod )
969
- is_end_per = isinstance (end , ABCPeriod )
958
+ is_start_per = isinstance (start , Period )
959
+ is_end_per = isinstance (end , Period )
970
960
971
961
if is_start_per and is_end_per and start .freq != end .freq :
972
962
raise ValueError ("start and end must have same freq" )
0 commit comments