diff --git a/pandas/core/indexes/interval.py b/pandas/core/indexes/interval.py index 3ffb1160c14ce..47a554b9101c1 100644 --- a/pandas/core/indexes/interval.py +++ b/pandas/core/indexes/interval.py @@ -1289,10 +1289,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) diff --git a/pandas/core/indexes/period.py b/pandas/core/indexes/period.py index 41968c5972ea5..590b711d6d45a 100644 --- a/pandas/core/indexes/period.py +++ b/pandas/core/indexes/period.py @@ -148,7 +148,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) @@ -161,6 +161,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 diff --git a/pandas/core/reshape/concat.py b/pandas/core/reshape/concat.py index 13052c23a9f11..77b1076920f20 100644 --- a/pandas/core/reshape/concat.py +++ b/pandas/core/reshape/concat.py @@ -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 @@ -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 # --------------------------------------------------------------------- @@ -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] @@ -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) @@ -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 = {} @@ -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: diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py index 20c0297448494..2110a2d400be8 100644 --- a/pandas/io/parsers.py +++ b/pandas/io/parsers.py @@ -2177,7 +2177,7 @@ def TextParser(*args, **kwds): return TextFileReader(*args, **kwds) -def count_empty_vals(vals): +def count_empty_vals(vals) -> int: return sum(1 for v in vals if v == "" or v is None) diff --git a/setup.cfg b/setup.cfg index 8c86a723bbb59..d8525c12cf13e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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 @@ -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