Skip to content

Commit 1a576eb

Browse files
TYP: check_untyped_defs core.dtypes.cast (#35992)
1 parent 5a9ee74 commit 1a576eb

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

pandas/core/indexes/datetimes.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _new_DatetimeIndex(cls, d):
7575
+ [
7676
method
7777
for method in DatetimeArray._datetimelike_methods
78-
if method not in ("tz_localize",)
78+
if method not in ("tz_localize", "tz_convert")
7979
],
8080
DatetimeArray,
8181
wrap=True,
@@ -228,6 +228,11 @@ class DatetimeIndex(DatetimeTimedeltaMixin):
228228
# --------------------------------------------------------------------
229229
# methods that dispatch to array and wrap result in DatetimeIndex
230230

231+
@doc(DatetimeArray.tz_convert)
232+
def tz_convert(self, tz) -> "DatetimeIndex":
233+
arr = self._data.tz_convert(tz)
234+
return type(self)._simple_new(arr, name=self.name)
235+
231236
@doc(DatetimeArray.tz_localize)
232237
def tz_localize(
233238
self, tz, ambiguous="raise", nonexistent="raise"

pandas/core/tools/datetimes.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,7 @@ def _convert_listlike_datetimes(
307307
if not isinstance(arg, (DatetimeArray, DatetimeIndex)):
308308
return DatetimeIndex(arg, tz=tz, name=name)
309309
if tz == "utc":
310-
# error: Item "DatetimeIndex" of "Union[DatetimeArray, DatetimeIndex]" has
311-
# no attribute "tz_convert"
312-
arg = arg.tz_convert(None).tz_localize(tz) # type: ignore[union-attr]
310+
arg = arg.tz_convert(None).tz_localize(tz)
313311
return arg
314312

315313
elif is_datetime64_ns_dtype(arg_dtype):

setup.cfg

-3
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ check_untyped_defs=False
157157
[mypy-pandas.core.computation.scope]
158158
check_untyped_defs=False
159159

160-
[mypy-pandas.core.dtypes.cast]
161-
check_untyped_defs=False
162-
163160
[mypy-pandas.core.frame]
164161
check_untyped_defs=False
165162

0 commit comments

Comments
 (0)