Skip to content

Commit 96644d0

Browse files
TYP: check_untyped_defs core.tools.datetimes (#32101)
1 parent 421f654 commit 96644d0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

pandas/core/tools/datetimes.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from datetime import datetime, time
33
from functools import partial
44
from itertools import islice
5-
from typing import Optional, TypeVar, Union
5+
from typing import List, Optional, TypeVar, Union
66

77
import numpy as np
88

@@ -296,7 +296,9 @@ def _convert_listlike_datetimes(
296296
if not isinstance(arg, (DatetimeArray, DatetimeIndex)):
297297
return DatetimeIndex(arg, tz=tz, name=name)
298298
if tz == "utc":
299-
arg = arg.tz_convert(None).tz_localize(tz)
299+
# error: Item "DatetimeIndex" of "Union[DatetimeArray, DatetimeIndex]" has
300+
# no attribute "tz_convert"
301+
arg = arg.tz_convert(None).tz_localize(tz) # type: ignore
300302
return arg
301303

302304
elif is_datetime64_ns_dtype(arg):
@@ -307,7 +309,9 @@ def _convert_listlike_datetimes(
307309
pass
308310
elif tz:
309311
# DatetimeArray, DatetimeIndex
310-
return arg.tz_localize(tz)
312+
# error: Item "DatetimeIndex" of "Union[DatetimeArray, DatetimeIndex]" has
313+
# no attribute "tz_localize"
314+
return arg.tz_localize(tz) # type: ignore
311315

312316
return arg
313317

@@ -826,18 +830,18 @@ def f(value):
826830
required = ["year", "month", "day"]
827831
req = sorted(set(required) - set(unit_rev.keys()))
828832
if len(req):
829-
required = ",".join(req)
833+
_required = ",".join(req)
830834
raise ValueError(
831835
"to assemble mappings requires at least that "
832-
f"[year, month, day] be specified: [{required}] is missing"
836+
f"[year, month, day] be specified: [{_required}] is missing"
833837
)
834838

835839
# keys we don't recognize
836840
excess = sorted(set(unit_rev.keys()) - set(_unit_map.values()))
837841
if len(excess):
838-
excess = ",".join(excess)
842+
_excess = ",".join(excess)
839843
raise ValueError(
840-
f"extra keys have been passed to the datetime assemblage: [{excess}]"
844+
f"extra keys have been passed to the datetime assemblage: [{_excess}]"
841845
)
842846

843847
def coerce(values):
@@ -992,7 +996,7 @@ def _convert_listlike(arg, format):
992996
if infer_time_format and format is None:
993997
format = _guess_time_format_for_array(arg)
994998

995-
times = []
999+
times: List[Optional[time]] = []
9961000
if format is not None:
9971001
for element in arg:
9981002
try:

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,6 @@ check_untyped_defs=False
231231
[mypy-pandas.core.strings]
232232
check_untyped_defs=False
233233

234-
[mypy-pandas.core.tools.datetimes]
235-
check_untyped_defs=False
236-
237234
[mypy-pandas.core.window.common]
238235
check_untyped_defs=False
239236

0 commit comments

Comments
 (0)