Skip to content

Commit 4ada17e

Browse files
committed
mypy fixup
1 parent f768a2f commit 4ada17e

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

pandas/core/arrays/datetimelike.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,9 +2140,9 @@ def unit(self) -> TimeUnit:
21402140
>>> idx.as_unit("s").unit
21412141
's'
21422142
"""
2143-
# error: Argument 1 to "dtype_to_unit" has incompatible type
2144-
# "ExtensionDtype"; expected "Union[DatetimeTZDtype, dtype[Any]]"
2145-
return dtype_to_unit(self.dtype) # type: ignore[arg-type]
2143+
# error: Incompatible return value type (got "str", expected
2144+
# "Literal['s', 'ms', 'us', 'ns']") [return-value]
2145+
return dtype_to_unit(self.dtype) # type: ignore[return-value]
21462146

21472147
def as_unit(self, unit: TimeUnit, round_ok: bool = True) -> Self:
21482148
"""

pandas/core/arrays/datetimes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ def _from_sequence_not_strict(
395395
result = cls._simple_new(subarr, freq=inferred_freq, dtype=data_dtype)
396396
if unit is not None and unit != result.unit:
397397
# If unit was specified in user-passed dtype, cast to it here
398-
result = result.as_unit(unit)
398+
# error: Argument 1 to "as_unit" of "TimelikeOps" has
399+
# incompatible type "str"; expected "Literal['s', 'ms', 'us', 'ns']"
400+
# [arg-type]
401+
result = result.as_unit(unit) # type: ignore[arg-type]
399402

400403
validate_kwds = {"ambiguous": ambiguous}
401404
result._maybe_pin_freq(freq, validate_kwds)

pandas/core/arrays/period.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,9 @@ def astype(self, dtype, copy: bool = True):
962962
# GH#45038 match PeriodIndex behavior.
963963
tz = getattr(dtype, "tz", None)
964964
unit = dtl.dtype_to_unit(dtype)
965-
return self.to_timestamp().tz_localize(tz).as_unit(unit)
965+
# error: Argument 1 to "as_unit" of "TimelikeOps" has incompatible
966+
# type "str"; expected "Literal['s', 'ms', 'us', 'ns']" [arg-type]
967+
return self.to_timestamp().tz_localize(tz).as_unit(unit) # type: ignore[arg-type]
966968

967969
return super().astype(dtype, copy=copy)
968970

0 commit comments

Comments
 (0)