From a08db9766d30c828d155a33e64fa1b895ea2576e Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 19 Feb 2020 12:32:28 +0000 Subject: [PATCH] TYP: check_untyped_defs core.tools.datetimes --- pandas/core/tools/datetimes.py | 20 ++++++++++++-------- setup.cfg | 3 --- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pandas/core/tools/datetimes.py b/pandas/core/tools/datetimes.py index 6d45ddd29d783..b10b736b9134e 100644 --- a/pandas/core/tools/datetimes.py +++ b/pandas/core/tools/datetimes.py @@ -2,7 +2,7 @@ from datetime import datetime, time from functools import partial from itertools import islice -from typing import Optional, TypeVar, Union +from typing import List, Optional, TypeVar, Union import numpy as np @@ -296,7 +296,9 @@ def _convert_listlike_datetimes( if not isinstance(arg, (DatetimeArray, DatetimeIndex)): return DatetimeIndex(arg, tz=tz, name=name) if tz == "utc": - arg = arg.tz_convert(None).tz_localize(tz) + # error: Item "DatetimeIndex" of "Union[DatetimeArray, DatetimeIndex]" has + # no attribute "tz_convert" + arg = arg.tz_convert(None).tz_localize(tz) # type: ignore return arg elif is_datetime64_ns_dtype(arg): @@ -307,7 +309,9 @@ def _convert_listlike_datetimes( pass elif tz: # DatetimeArray, DatetimeIndex - return arg.tz_localize(tz) + # error: Item "DatetimeIndex" of "Union[DatetimeArray, DatetimeIndex]" has + # no attribute "tz_localize" + return arg.tz_localize(tz) # type: ignore return arg @@ -826,18 +830,18 @@ def f(value): required = ["year", "month", "day"] req = sorted(set(required) - set(unit_rev.keys())) if len(req): - required = ",".join(req) + _required = ",".join(req) raise ValueError( "to assemble mappings requires at least that " - f"[year, month, day] be specified: [{required}] is missing" + f"[year, month, day] be specified: [{_required}] is missing" ) # keys we don't recognize excess = sorted(set(unit_rev.keys()) - set(_unit_map.values())) if len(excess): - excess = ",".join(excess) + _excess = ",".join(excess) raise ValueError( - f"extra keys have been passed to the datetime assemblage: [{excess}]" + f"extra keys have been passed to the datetime assemblage: [{_excess}]" ) def coerce(values): @@ -992,7 +996,7 @@ def _convert_listlike(arg, format): if infer_time_format and format is None: format = _guess_time_format_for_array(arg) - times = [] + times: List[Optional[time]] = [] if format is not None: for element in arg: try: diff --git a/setup.cfg b/setup.cfg index 4a900e581c353..32efec7d2cf0d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -234,9 +234,6 @@ check_untyped_defs=False [mypy-pandas.core.strings] check_untyped_defs=False -[mypy-pandas.core.tools.datetimes] -check_untyped_defs=False - [mypy-pandas.core.window.common] check_untyped_defs=False