Skip to content

Commit

Permalink
TYP: indexes (pandas-dev#37224)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Oct 29, 2020
1 parent 290c58a commit 5532ae8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
6 changes: 2 additions & 4 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,10 +1290,8 @@ def interval_range(
else:
# delegate to the appropriate range function
if isinstance(endpoint, Timestamp):
range_func = date_range
breaks = date_range(start=start, end=end, periods=periods, freq=freq)
else:
range_func = timedelta_range

breaks = range_func(start=start, end=end, periods=periods, freq=freq)
breaks = timedelta_range(start=start, end=end, periods=periods, freq=freq)

return IntervalIndex.from_breaks(breaks, name=name, closed=closed)
20 changes: 19 additions & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class PeriodIndex(DatetimeIndexOpsMixin, Int64Index):
_supports_partial_string_indexing = True

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

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

# error: Decorated property not supported [misc]
@property # type:ignore[misc]
@doc(PeriodArray.hour.fget)
def hour(self) -> Int64Index:
return Int64Index(self._data.hour, name=self.name)

# error: Decorated property not supported [misc]
@property # type:ignore[misc]
@doc(PeriodArray.minute.fget)
def minute(self) -> Int64Index:
return Int64Index(self._data.minute, name=self.name)

# error: Decorated property not supported [misc]
@property # type:ignore[misc]
@doc(PeriodArray.second.fget)
def second(self) -> Int64Index:
return Int64Index(self._data.second, name=self.name)

# ------------------------------------------------------------------------
# Index Constructors

Expand Down
15 changes: 10 additions & 5 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from collections import abc
from typing import TYPE_CHECKING, Iterable, List, Mapping, Union, overload
from typing import TYPE_CHECKING, Iterable, List, Mapping, Type, Union, cast, overload

import numpy as np

Expand All @@ -30,7 +30,7 @@
from pandas.core.internals import concatenate_block_managers

if TYPE_CHECKING:
from pandas import DataFrame
from pandas import DataFrame, Series
from pandas.core.generic import NDFrame

# ---------------------------------------------------------------------
Expand Down Expand Up @@ -455,14 +455,17 @@ def __init__(
self.new_axes = self._get_new_axes()

def get_result(self):
cons: Type[FrameOrSeriesUnion]
sample: FrameOrSeriesUnion

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

# stack blocks
if self.bm_axis == 0:
name = com.consensus_name_attr(self.objs)
cons = self.objs[0]._constructor
cons = sample._constructor

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

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

# GH28330 Preserves subclassed objects through concat
cons = self.objs[0]._constructor_expanddim
cons = sample._constructor_expanddim

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

# combine block managers
else:
sample = cast("DataFrame", self.objs[0])

mgrs_indexers = []
for obj in self.objs:
indexers = {}
Expand All @@ -506,7 +511,7 @@ def get_result(self):
if not self.copy:
new_data._consolidate_inplace()

cons = self.objs[0]._constructor
cons = sample._constructor
return cons(new_data).__finalize__(self, method="concat")

def _get_result_dim(self) -> int:
Expand Down
9 changes: 0 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,12 @@ check_untyped_defs=False
[mypy-pandas.core.indexes.extension]
check_untyped_defs=False

[mypy-pandas.core.indexes.interval]
check_untyped_defs=False

[mypy-pandas.core.indexes.multi]
check_untyped_defs=False

[mypy-pandas.core.resample]
check_untyped_defs=False

[mypy-pandas.core.reshape.concat]
check_untyped_defs=False

[mypy-pandas.core.reshape.merge]
check_untyped_defs=False

Expand All @@ -214,9 +208,6 @@ check_untyped_defs=False
[mypy-pandas.io.parsers]
check_untyped_defs=False

[mypy-pandas.plotting._matplotlib.converter]
check_untyped_defs=False

[mypy-pandas.plotting._matplotlib.core]
check_untyped_defs=False

Expand Down

0 comments on commit 5532ae8

Please sign in to comment.