@@ -327,7 +327,7 @@ def _format_native_types(self, na_rep="NaT", date_format=None):
327
327
"""
328
328
raise AbstractMethodError (self )
329
329
330
- def _formatter (self , boxed = False ):
330
+ def _formatter (self , boxed : bool = False ):
331
331
# TODO: Remove Datetime & DatetimeTZ formatters.
332
332
return "'{}'" .format
333
333
@@ -354,7 +354,7 @@ def __getitem__(
354
354
result ._freq = self ._get_getitem_freq (key )
355
355
return result
356
356
357
- def _get_getitem_freq (self , key ):
357
+ def _get_getitem_freq (self , key ) -> Optional [ BaseOffset ] :
358
358
"""
359
359
Find the `freq` attribute to assign to the result of a __getitem__ lookup.
360
360
"""
@@ -406,7 +406,7 @@ def _maybe_clear_freq(self):
406
406
# DatetimeArray and TimedeltaArray
407
407
pass
408
408
409
- def astype (self , dtype , copy = True ):
409
+ def astype (self , dtype , copy : bool = True ):
410
410
# Some notes on cases we don't have to handle here in the base class:
411
411
# 1. PeriodArray.astype handles period -> period
412
412
# 2. DatetimeArray.astype handles conversion between tz.
@@ -545,7 +545,7 @@ def _values_for_factorize(self):
545
545
546
546
@classmethod
547
547
def _from_factorized (
548
- cls : Type [DatetimeLikeArrayT ], values , original
548
+ cls : Type [DatetimeLikeArrayT ], values , original : DatetimeLikeArrayT
549
549
) -> DatetimeLikeArrayT :
550
550
return cls (values , dtype = original .dtype )
551
551
@@ -939,7 +939,7 @@ def freq(self, value):
939
939
self ._freq = value
940
940
941
941
@property
942
- def freqstr (self ):
942
+ def freqstr (self ) -> Optional [ str ] :
943
943
"""
944
944
Return the frequency object as a string if its set, otherwise None.
945
945
"""
@@ -948,7 +948,7 @@ def freqstr(self):
948
948
return self .freq .freqstr
949
949
950
950
@property # NB: override with cache_readonly in immutable subclasses
951
- def inferred_freq (self ):
951
+ def inferred_freq (self ) -> Optional [ str ] :
952
952
"""
953
953
Tries to return a string representing a frequency guess,
954
954
generated by infer_freq. Returns None if it can't autodetect the
@@ -963,8 +963,11 @@ def inferred_freq(self):
963
963
964
964
@property # NB: override with cache_readonly in immutable subclasses
965
965
def _resolution_obj (self ) -> Optional [Resolution ]:
966
+ freqstr = self .freqstr
967
+ if freqstr is None :
968
+ return None
966
969
try :
967
- return Resolution .get_reso_from_freq (self . freqstr )
970
+ return Resolution .get_reso_from_freq (freqstr )
968
971
except KeyError :
969
972
return None
970
973
@@ -1241,7 +1244,7 @@ def _addsub_object_array(self, other: np.ndarray, op):
1241
1244
)
1242
1245
return result
1243
1246
1244
- def _time_shift (self , periods , freq = None ):
1247
+ def _time_shift (self , periods : int , freq = None ):
1245
1248
"""
1246
1249
Shift each value by `periods`.
1247
1250
@@ -1440,7 +1443,7 @@ def __isub__(self, other):
1440
1443
# --------------------------------------------------------------
1441
1444
# Reductions
1442
1445
1443
- def min (self , * , axis = None , skipna = True , ** kwargs ):
1446
+ def min (self , * , axis : Optional [ int ] = None , skipna : bool = True , ** kwargs ):
1444
1447
"""
1445
1448
Return the minimum value of the Array or minimum along
1446
1449
an axis.
@@ -1469,7 +1472,7 @@ def min(self, *, axis=None, skipna=True, **kwargs):
1469
1472
result = nanops .nanmin (self ._ndarray , axis = axis , skipna = skipna )
1470
1473
return self ._wrap_reduction_result (axis , result )
1471
1474
1472
- def max (self , * , axis = None , skipna = True , ** kwargs ):
1475
+ def max (self , * , axis : Optional [ int ] = None , skipna : bool = True , ** kwargs ):
1473
1476
"""
1474
1477
Return the maximum value of the Array or maximum along
1475
1478
an axis.
@@ -1500,7 +1503,7 @@ def max(self, *, axis=None, skipna=True, **kwargs):
1500
1503
result = nanops .nanmax (self ._ndarray , axis = axis , skipna = skipna )
1501
1504
return self ._wrap_reduction_result (axis , result )
1502
1505
1503
- def mean (self , * , skipna = True , axis : Optional [int ] = 0 ):
1506
+ def mean (self , * , skipna : bool = True , axis : Optional [int ] = 0 ):
1504
1507
"""
1505
1508
Return the mean value of the Array.
1506
1509
@@ -1568,7 +1571,7 @@ class DatelikeOps(DatetimeLikeArrayMixin):
1568
1571
URL = "https://docs.python.org/3/library/datetime.html"
1569
1572
"#strftime-and-strptime-behavior"
1570
1573
)
1571
- def strftime (self , date_format ) :
1574
+ def strftime (self , date_format : str ) -> np . ndarray :
1572
1575
"""
1573
1576
Convert to Index using specified date_format.
1574
1577
@@ -1760,7 +1763,7 @@ def all(self, *, axis: Optional[int] = None, skipna: bool = True):
1760
1763
# --------------------------------------------------------------
1761
1764
# Frequency Methods
1762
1765
1763
- def _maybe_clear_freq (self ):
1766
+ def _maybe_clear_freq (self ) -> None :
1764
1767
self ._freq = None
1765
1768
1766
1769
def _with_freq (self , freq ):
0 commit comments