Skip to content

TYP: check_untyped_defs core.reshape.reshape #31367

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

Merged
merged 3 commits into from
Jan 31, 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
15 changes: 9 additions & 6 deletions pandas/core/reshape/reshape.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from functools import partial
import itertools
from typing import List
from typing import List, Optional, Union

import numpy as np

Expand Down Expand Up @@ -375,6 +375,7 @@ def _unstack_multiple(data, clocs, fill_value=None):
unstcols = unstacked.index
else:
unstcols = unstacked.columns
assert isinstance(unstcols, MultiIndex) # for mypy
new_levels = [unstcols.levels[0]] + clevels
new_names = [data.columns.name] + cnames

Expand Down Expand Up @@ -433,15 +434,14 @@ def _unstack_frame(obj, level, fill_value=None):
blocks = obj._data.unstack(unstacker, fill_value=fill_value)
return obj._constructor(blocks)
else:
unstacker = _Unstacker(
return _Unstacker(
obj.values,
obj.index,
level=level,
value_columns=obj.columns,
fill_value=fill_value,
constructor=obj._constructor,
)
return unstacker.get_result()
).get_result()


def _unstack_extension_series(series, level, fill_value):
Expand Down Expand Up @@ -902,9 +902,10 @@ def check_len(item, name):
elif isinstance(prefix_sep, dict):
prefix_sep = [prefix_sep[col] for col in data_to_encode.columns]

with_dummies: List[DataFrame]
if data_to_encode.shape == data.shape:
# Encoding the entire df, do not prepend any dropped columns
with_dummies: List[DataFrame] = []
with_dummies = []
elif columns is not None:
# Encoding only cols specified in columns. Get all cols not in
# columns to prepend to result.
Expand Down Expand Up @@ -994,13 +995,15 @@ def _make_col_name(prefix, prefix_sep, level) -> str:

dummy_cols = [_make_col_name(prefix, prefix_sep, level) for level in levels]

index: Optional[Index]
if isinstance(data, Series):
index = data.index
else:
index = None

if sparse:

fill_value: Union[bool, float, int]
if is_integer_dtype(dtype):
fill_value = 0
elif dtype == bool:
Expand All @@ -1010,7 +1013,7 @@ def _make_col_name(prefix, prefix_sep, level) -> str:

sparse_series = []
N = len(data)
sp_indices = [[] for _ in range(len(dummy_cols))]
sp_indices: List[List] = [[] for _ in range(len(dummy_cols))]
mask = codes != -1
codes = codes[mask]
n_idx = np.arange(N)[mask]
Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,6 @@ check_untyped_defs=False
[mypy-pandas.core.reshape.merge]
check_untyped_defs=False

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

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

Expand Down