|
85 | 85 | IntervalClosedType, |
86 | 86 | Ordered, |
87 | 87 | Scalar, |
| 88 | + TimeUnit, |
88 | 89 | npt, |
89 | 90 | type_t, |
90 | 91 | ) |
@@ -780,10 +781,10 @@ def base(self) -> DtypeObj: # type: ignore[override] |
780 | 781 | def str(self) -> str: # type: ignore[override] |
781 | 782 | return f"|M8[{self.unit}]" |
782 | 783 |
|
783 | | - def __init__(self, unit: str_type | DatetimeTZDtype = "ns", tz=None) -> None: |
| 784 | + def __init__(self, unit: TimeUnit | DatetimeTZDtype = "ns", tz=None) -> None: |
784 | 785 | if isinstance(unit, DatetimeTZDtype): |
785 | 786 | # error: "str" has no attribute "tz" |
786 | | - unit, tz = unit.unit, unit.tz # type: ignore[attr-defined] |
| 787 | + unit, tz = unit.unit, unit.tz # type: ignore[union-attr] |
787 | 788 |
|
788 | 789 | if unit != "ns": |
789 | 790 | if isinstance(unit, str) and tz is None: |
@@ -820,7 +821,7 @@ def _creso(self) -> int: |
820 | 821 | return abbrev_to_npy_unit(self.unit) |
821 | 822 |
|
822 | 823 | @property |
823 | | - def unit(self) -> str_type: |
| 824 | + def unit(self) -> TimeUnit: |
824 | 825 | """ |
825 | 826 | The precision of the datetime data. |
826 | 827 |
|
@@ -894,7 +895,8 @@ def construct_from_string(cls, string: str_type) -> DatetimeTZDtype: |
894 | 895 | if match: |
895 | 896 | d = match.groupdict() |
896 | 897 | try: |
897 | | - return cls(unit=d["unit"], tz=d["tz"]) |
| 898 | + unit = cast("TimeUnit", d["unit"]) |
| 899 | + return cls(unit=unit, tz=d["tz"]) |
898 | 900 | except (KeyError, TypeError, ValueError) as err: |
899 | 901 | # KeyError if maybe_get_tz tries and fails to get a |
900 | 902 | # zoneinfo timezone (actually zoneinfo.ZoneInfoNotFoundError). |
@@ -971,6 +973,7 @@ def _get_common_dtype(self, dtypes: list[DtypeObj]) -> DtypeObj | None: |
971 | 973 | if all(isinstance(t, DatetimeTZDtype) and t.tz == self.tz for t in dtypes): |
972 | 974 | np_dtype = np.max([cast(DatetimeTZDtype, t).base for t in [self, *dtypes]]) |
973 | 975 | unit = np.datetime_data(np_dtype)[0] |
| 976 | + unit = cast("TimeUnit", unit) |
974 | 977 | return type(self)(unit=unit, tz=self.tz) |
975 | 978 | return super()._get_common_dtype(dtypes) |
976 | 979 |
|
|
0 commit comments