Skip to content

Commit e1624e5

Browse files
authored
TYP: DatetimeIndex, TimedeltaIndex (#37365)
1 parent 12ce683 commit e1624e5

File tree

3 files changed

+30
-24
lines changed

3 files changed

+30
-24
lines changed

pandas/core/indexes/datetimelike.py

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
"""
22
Base and utility classes for tseries type pandas objects.
33
"""
4-
from datetime import datetime, tzinfo
5-
from typing import TYPE_CHECKING, Any, List, Optional, TypeVar, Union, cast
4+
from datetime import datetime
5+
from typing import TYPE_CHECKING, Any, List, Optional, Tuple, TypeVar, Union, cast
66

77
import numpy as np
88

99
from pandas._libs import NaT, Timedelta, iNaT, join as libjoin, lib
10-
from pandas._libs.tslibs import BaseOffset, Resolution, Tick, timezones
10+
from pandas._libs.tslibs import BaseOffset, Resolution, Tick
1111
from pandas._typing import Callable, Label
1212
from pandas.compat.numpy import function as nv
1313
from pandas.errors import AbstractMethodError
@@ -672,8 +672,6 @@ class DatetimeTimedeltaMixin(DatetimeIndexOpsMixin, Int64Index):
672672
but not PeriodIndex
673673
"""
674674

675-
tz: Optional[tzinfo]
676-
677675
# Compat for frequency inference, see GH#23789
678676
_is_monotonic_increasing = Index.is_monotonic_increasing
679677
_is_monotonic_decreasing = Index.is_monotonic_decreasing
@@ -931,22 +929,9 @@ def join(
931929
sort=sort,
932930
)
933931

934-
def _maybe_utc_convert(self, other):
935-
this = self
936-
if not hasattr(self, "tz"):
937-
return this, other
938-
939-
if isinstance(other, type(self)):
940-
if self.tz is not None:
941-
if other.tz is None:
942-
raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex")
943-
elif other.tz is not None:
944-
raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex")
945-
946-
if not timezones.tz_compare(self.tz, other.tz):
947-
this = self.tz_convert("UTC")
948-
other = other.tz_convert("UTC")
949-
return this, other
932+
def _maybe_utc_convert(self: _T, other: Index) -> Tuple[_T, Index]:
933+
# Overridden by DatetimeIndex
934+
return self, other
950935

951936
# --------------------------------------------------------------------
952937
# List-Like Methods

pandas/core/indexes/datetimes.py

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
from datetime import date, datetime, time, timedelta, tzinfo
22
import operator
3-
from typing import TYPE_CHECKING, Optional
3+
from typing import TYPE_CHECKING, Optional, Tuple
44
import warnings
55

66
import numpy as np
77

88
from pandas._libs import NaT, Period, Timestamp, index as libindex, lib
9-
from pandas._libs.tslibs import Resolution, ints_to_pydatetime, parsing, to_offset
9+
from pandas._libs.tslibs import (
10+
Resolution,
11+
ints_to_pydatetime,
12+
parsing,
13+
timezones,
14+
to_offset,
15+
)
1016
from pandas._libs.tslibs.offsets import prefix_mapping
1117
from pandas._typing import DtypeObj, Label
1218
from pandas.errors import InvalidIndexError
@@ -411,6 +417,21 @@ def union_many(self, others):
411417
return this.rename(res_name)
412418
return this
413419

420+
def _maybe_utc_convert(self, other: Index) -> Tuple["DatetimeIndex", Index]:
421+
this = self
422+
423+
if isinstance(other, DatetimeIndex):
424+
if self.tz is not None:
425+
if other.tz is None:
426+
raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex")
427+
elif other.tz is not None:
428+
raise TypeError("Cannot join tz-naive with tz-aware DatetimeIndex")
429+
430+
if not timezones.tz_compare(self.tz, other.tz):
431+
this = self.tz_convert("UTC")
432+
other = other.tz_convert("UTC")
433+
return this, other
434+
414435
# --------------------------------------------------------------------
415436

416437
def _get_time_micros(self):

pandas/io/parsers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ def TextParser(*args, **kwds):
21772177
return TextFileReader(*args, **kwds)
21782178

21792179

2180-
def count_empty_vals(vals):
2180+
def count_empty_vals(vals) -> int:
21812181
return sum(1 for v in vals if v == "" or v is None)
21822182

21832183

0 commit comments

Comments
 (0)