Skip to content

Commit 324dd6c

Browse files
jbrockmendelKevin D Smith
authored and
Kevin D Smith
committed
TYP: indexes (pandas-dev#37224)
1 parent fded0c4 commit 324dd6c

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

pandas/core/indexes/interval.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1290,10 +1290,8 @@ def interval_range(
12901290
else:
12911291
# delegate to the appropriate range function
12921292
if isinstance(endpoint, Timestamp):
1293-
range_func = date_range
1293+
breaks = date_range(start=start, end=end, periods=periods, freq=freq)
12941294
else:
1295-
range_func = timedelta_range
1296-
1297-
breaks = range_func(start=start, end=end, periods=periods, freq=freq)
1295+
breaks = timedelta_range(start=start, end=end, periods=periods, freq=freq)
12981296

12991297
return IntervalIndex.from_breaks(breaks, name=name, closed=closed)

pandas/core/indexes/period.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index):
150150
_supports_partial_string_indexing = True
151151

152152
# --------------------------------------------------------------------
153-
# methods that dispatch to array and wrap result in PeriodIndex
153+
# methods that dispatch to array and wrap result in Index
154154
# These are defined here instead of via inherit_names for mypy
155155

156156
@doc(PeriodArray.asfreq)
@@ -163,6 +163,24 @@ def to_timestamp(self, freq=None, how="start") -> DatetimeIndex:
163163
arr = self._data.to_timestamp(freq, how)
164164
return DatetimeIndex._simple_new(arr, name=self.name)
165165

166+
# error: Decorated property not supported [misc]
167+
@property # type:ignore[misc]
168+
@doc(PeriodArray.hour.fget)
169+
def hour(self) -> Int64Index:
170+
return Int64Index(self._data.hour, name=self.name)
171+
172+
# error: Decorated property not supported [misc]
173+
@property # type:ignore[misc]
174+
@doc(PeriodArray.minute.fget)
175+
def minute(self) -> Int64Index:
176+
return Int64Index(self._data.minute, name=self.name)
177+
178+
# error: Decorated property not supported [misc]
179+
@property # type:ignore[misc]
180+
@doc(PeriodArray.second.fget)
181+
def second(self) -> Int64Index:
182+
return Int64Index(self._data.second, name=self.name)
183+
166184
# ------------------------------------------------------------------------
167185
# Index Constructors
168186

pandas/core/reshape/concat.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44

55
from collections import abc
6-
from typing import TYPE_CHECKING, Iterable, List, Mapping, Union, overload
6+
from typing import TYPE_CHECKING, Iterable, List, Mapping, Type, Union, cast, overload
77

88
import numpy as np
99

@@ -30,7 +30,7 @@
3030
from pandas.core.internals import concatenate_block_managers
3131

3232
if TYPE_CHECKING:
33-
from pandas import DataFrame
33+
from pandas import DataFrame, Series
3434
from pandas.core.generic import NDFrame
3535

3636
# ---------------------------------------------------------------------
@@ -455,14 +455,17 @@ def __init__(
455455
self.new_axes = self._get_new_axes()
456456

457457
def get_result(self):
458+
cons: Type[FrameOrSeriesUnion]
459+
sample: FrameOrSeriesUnion
458460

459461
# series only
460462
if self._is_series:
463+
sample = cast("Series", self.objs[0])
461464

462465
# stack blocks
463466
if self.bm_axis == 0:
464467
name = com.consensus_name_attr(self.objs)
465-
cons = self.objs[0]._constructor
468+
cons = sample._constructor
466469

467470
arrs = [ser._values for ser in self.objs]
468471

@@ -475,7 +478,7 @@ def get_result(self):
475478
data = dict(zip(range(len(self.objs)), self.objs))
476479

477480
# GH28330 Preserves subclassed objects through concat
478-
cons = self.objs[0]._constructor_expanddim
481+
cons = sample._constructor_expanddim
479482

480483
index, columns = self.new_axes
481484
df = cons(data, index=index)
@@ -484,6 +487,8 @@ def get_result(self):
484487

485488
# combine block managers
486489
else:
490+
sample = cast("DataFrame", self.objs[0])
491+
487492
mgrs_indexers = []
488493
for obj in self.objs:
489494
indexers = {}
@@ -506,7 +511,7 @@ def get_result(self):
506511
if not self.copy:
507512
new_data._consolidate_inplace()
508513

509-
cons = self.objs[0]._constructor
514+
cons = sample._constructor
510515
return cons(new_data).__finalize__(self, method="concat")
511516

512517
def _get_result_dim(self) -> int:

setup.cfg

-9
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,12 @@ check_untyped_defs=False
181181
[mypy-pandas.core.indexes.extension]
182182
check_untyped_defs=False
183183

184-
[mypy-pandas.core.indexes.interval]
185-
check_untyped_defs=False
186-
187184
[mypy-pandas.core.indexes.multi]
188185
check_untyped_defs=False
189186

190187
[mypy-pandas.core.resample]
191188
check_untyped_defs=False
192189

193-
[mypy-pandas.core.reshape.concat]
194-
check_untyped_defs=False
195-
196190
[mypy-pandas.core.reshape.merge]
197191
check_untyped_defs=False
198192

@@ -214,9 +208,6 @@ check_untyped_defs=False
214208
[mypy-pandas.io.parsers]
215209
check_untyped_defs=False
216210

217-
[mypy-pandas.plotting._matplotlib.converter]
218-
check_untyped_defs=False
219-
220211
[mypy-pandas.plotting._matplotlib.core]
221212
check_untyped_defs=False
222213

0 commit comments

Comments
 (0)