Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TYP: indexes #37224

Merged
merged 14 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions pandas/core/indexes/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
20 changes: 19 additions & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need to remove from inherit_names?

and maybe update comment on L151

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated comment; removing from inherit_names is a PITA since it isnt there directly. harmless to have it there.

@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
2 changes: 1 addition & 1 deletion pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


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