3131 pandas_dtype ,
3232)
3333from 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
4135from pandas .core .dtypes .missing import isna , notna
4236
4337import pandas .core .algorithms as algos
4842from pandas .tseries .offsets import DateOffset , Tick , _delta_to_tick
4943
5044
51- def _field_accessor (name , alias , docstring = None ):
45+ def _field_accessor (name : str , alias : int , docstring = None ):
5246 def f (self ):
5347 base , mult = libfrequencies .get_freq_code (self .freq )
5448 result = get_period_field_arr (alias , self .asi8 , base )
@@ -170,7 +164,7 @@ def __init__(self, values, freq=None, dtype=None, copy=False):
170164 self ._dtype = PeriodDtype (freq )
171165
172166 @classmethod
173- def _simple_new (cls , values : np .ndarray , freq = None , ** kwargs ):
167+ def _simple_new (cls , values : np .ndarray , freq = None , ** kwargs ) -> "PeriodArray" :
174168 # alias for PeriodArray.__init__
175169 assert isinstance (values , np .ndarray ) and values .dtype == "i8"
176170 return cls (values , freq = freq , ** kwargs )
@@ -181,7 +175,7 @@ def _from_sequence(
181175 scalars : Sequence [Optional [Period ]],
182176 dtype : Optional [PeriodDtype ] = None ,
183177 copy : bool = False ,
184- ) -> ABCPeriodArray :
178+ ) -> "PeriodArray" :
185179 if dtype :
186180 freq = dtype .freq
187181 else :
@@ -202,11 +196,13 @@ def _from_sequence(
202196 return cls (ordinals , freq = freq )
203197
204198 @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" :
206202 return cls ._from_sequence (strings , dtype , copy )
207203
208204 @classmethod
209- def _from_datetime64 (cls , data , freq , tz = None ):
205+ def _from_datetime64 (cls , data , freq , tz = None ) -> "PeriodArray" :
210206 """
211207 Construct a PeriodArray from a datetime64 array
212208
@@ -270,12 +266,12 @@ def _check_compatible_with(self, other, setitem: bool = False):
270266 # Data / Attributes
271267
272268 @cache_readonly
273- def dtype (self ):
269+ def dtype (self ) -> PeriodDtype :
274270 return self ._dtype
275271
276272 # error: Read-only property cannot override read-write property [misc]
277273 @property # type: ignore
278- def freq (self ):
274+ def freq (self ) -> DateOffset :
279275 """
280276 Return the frequency object for this PeriodArray.
281277 """
@@ -402,7 +398,7 @@ def __arrow_array__(self, type=None):
402398 daysinmonth = days_in_month
403399
404400 @property
405- def is_leap_year (self ):
401+ def is_leap_year (self ) -> np . ndarray :
406402 """
407403 Logical indicating if the date belongs to a leap year.
408404 """
@@ -458,12 +454,6 @@ def to_timestamp(self, freq=None, how="start"):
458454 new_data = libperiod .periodarr_to_dt64arr (new_data .asi8 , base )
459455 return DatetimeArray ._from_sequence (new_data , freq = "infer" )
460456
461- # --------------------------------------------------------------------
462- # Array-like / EA-Interface Methods
463-
464- def _values_for_argsort (self ):
465- return self ._data
466-
467457 # --------------------------------------------------------------------
468458
469459 def _time_shift (self , periods , freq = None ):
@@ -495,7 +485,7 @@ def _time_shift(self, periods, freq=None):
495485 def _box_func (self ):
496486 return lambda x : Period ._from_ordinal (ordinal = x , freq = self .freq )
497487
498- def asfreq (self , freq = None , how = "E" ):
488+ def asfreq (self , freq = None , how = "E" ) -> "PeriodArray" :
499489 """
500490 Convert the Period Array/Index to the specified frequency `freq`.
501491
@@ -557,7 +547,7 @@ def asfreq(self, freq=None, how="E"):
557547 # ------------------------------------------------------------------
558548 # Rendering Methods
559549
560- def _formatter (self , boxed = False ):
550+ def _formatter (self , boxed : bool = False ):
561551 if boxed :
562552 return str
563553 return "'{}'" .format
@@ -584,7 +574,7 @@ def _format_native_types(self, na_rep="NaT", date_format=None, **kwargs):
584574
585575 # ------------------------------------------------------------------
586576
587- def astype (self , dtype , copy = True ):
577+ def astype (self , dtype , copy : bool = True ):
588578 # We handle Period[T] -> Period[U]
589579 # Our parent handles everything else.
590580 dtype = pandas_dtype (dtype )
@@ -965,8 +955,8 @@ def _get_ordinal_range(start, end, periods, freq, mult=1):
965955 if end is not None :
966956 end = Period (end , freq )
967957
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 )
970960
971961 if is_start_per and is_end_per and start .freq != end .freq :
972962 raise ValueError ("start and end must have same freq" )
0 commit comments