From 30e2daa013dc6ad154dec80d3816bae679dff5c7 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Mon, 27 Jan 2020 21:01:43 +0000 Subject: [PATCH 1/2] TYP: check_untyped_defs core.reshape.reshape --- pandas/core/reshape/reshape.py | 15 +++++++++------ setup.cfg | 3 --- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index fab9f41cb6c4f..4864fa9fd714b 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -1,6 +1,6 @@ from functools import partial import itertools -from typing import List +from typing import List, Optional, Union import numpy as np @@ -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 @@ -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): @@ -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. @@ -994,6 +995,7 @@ 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: @@ -1001,6 +1003,7 @@ def _make_col_name(prefix, prefix_sep, level) -> str: if sparse: + fill_value: Union[bool, float] if is_integer_dtype(dtype): fill_value = 0 elif dtype == bool: @@ -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] diff --git a/setup.cfg b/setup.cfg index d0570cee6fe10..ccb5c4e5b06fd 100644 --- a/setup.cfg +++ b/setup.cfg @@ -243,9 +243,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 From 55dba724f49cf5a457c3614fdf36da9acc14c59f Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Tue, 28 Jan 2020 09:28:32 +0000 Subject: [PATCH 2/2] update fill_value annotation --- pandas/core/reshape/reshape.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/reshape/reshape.py b/pandas/core/reshape/reshape.py index 4864fa9fd714b..f00ff0d4ba5ed 100644 --- a/pandas/core/reshape/reshape.py +++ b/pandas/core/reshape/reshape.py @@ -1003,7 +1003,7 @@ def _make_col_name(prefix, prefix_sep, level) -> str: if sparse: - fill_value: Union[bool, float] + fill_value: Union[bool, float, int] if is_integer_dtype(dtype): fill_value = 0 elif dtype == bool: