|
1 | 1 | from datetime import timedelta
|
2 | 2 | import operator
|
3 |
| -from typing import Any, Callable, Optional, Sequence, Union |
| 3 | +from typing import Any, Callable, List, Optional, Sequence, Union |
4 | 4 |
|
5 | 5 | import numpy as np
|
6 | 6 |
|
|
23 | 23 | from pandas.core.dtypes.missing import isna, notna
|
24 | 24 |
|
25 | 25 | import pandas.core.algorithms as algos
|
26 |
| -from pandas.core.arrays import ExtensionArray, datetimelike as dtl |
| 26 | +from pandas.core.arrays import datetimelike as dtl |
27 | 27 | import pandas.core.common as com
|
28 | 28 |
|
29 | 29 | from pandas.tseries import frequencies
|
@@ -94,7 +94,7 @@ class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
|
94 | 94 |
|
95 | 95 | Parameters
|
96 | 96 | ----------
|
97 |
| - values : Union[PeriodArray, Series[period], ndarary[int], PeriodIndex] |
| 97 | + values : Union[PeriodArray, Series[period], ndarray[int], PeriodIndex] |
98 | 98 | The data to store. These should be arrays that can be directly
|
99 | 99 | converted to ordinals without inference or copy (PeriodArray,
|
100 | 100 | ndarray[int64]), or a box around such an array (Series[period],
|
@@ -135,7 +135,7 @@ class PeriodArray(dtl.DatetimeLikeArrayMixin, dtl.DatelikeOps):
|
135 | 135 | _scalar_type = Period
|
136 | 136 |
|
137 | 137 | # Names others delegate to us
|
138 |
| - _other_ops = [] |
| 138 | + _other_ops = [] # type: List[str] |
139 | 139 | _bool_ops = ['is_leap_year']
|
140 | 140 | _object_ops = ['start_time', 'end_time', 'freq']
|
141 | 141 | _field_ops = ['year', 'month', 'day', 'hour', 'minute', 'second',
|
@@ -276,7 +276,8 @@ def _check_compatible_with(self, other):
|
276 | 276 | def dtype(self):
|
277 | 277 | return self._dtype
|
278 | 278 |
|
279 |
| - @property |
| 279 | + # read-only property overwriting read/write |
| 280 | + @property # type: ignore |
280 | 281 | def freq(self):
|
281 | 282 | """
|
282 | 283 | Return the frequency object for this PeriodArray.
|
@@ -538,7 +539,8 @@ def _sub_period(self, other):
|
538 | 539 | @Appender(dtl.DatetimeLikeArrayMixin._addsub_int_array.__doc__)
|
539 | 540 | def _addsub_int_array(
|
540 | 541 | self,
|
541 |
| - other: Union[ExtensionArray, np.ndarray, ABCIndexClass], |
| 542 | + other: Union[ABCPeriodArray, ABCSeries, |
| 543 | + ABCPeriodIndex, np.ndarray], |
542 | 544 | op: Callable[[Any], Any]
|
543 | 545 | ) -> ABCPeriodArray:
|
544 | 546 | assert op in [operator.add, operator.sub]
|
@@ -778,7 +780,8 @@ def period_array(
|
778 | 780 | data = np.asarray(data)
|
779 | 781 |
|
780 | 782 | if freq:
|
781 |
| - dtype = PeriodDtype(freq) |
| 783 | + # typed Optional here because the else block below assigns None |
| 784 | + dtype = PeriodDtype(freq) # type: Optional[PeriodDtype] |
782 | 785 | else:
|
783 | 786 | dtype = None
|
784 | 787 |
|
|
0 commit comments