From 86d16e107f2ca829d9f177152513030bf29eb785 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 27 Nov 2019 19:45:48 +0000 Subject: [PATCH 1/3] TYP: some types for pandas/core/arrays/sparse/dtype.py --- pandas/core/arrays/sparse/dtype.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/arrays/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index 3b656705f5568..735d547dca298 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -1,7 +1,7 @@ """Sparse Dtype""" import re -from typing import Any +from typing import Any, Tuple, Union import numpy as np @@ -223,7 +223,7 @@ def construct_from_string(cls, string): raise TypeError(msg) @staticmethod - def _parse_subtype(dtype): + def _parse_subtype(dtype) -> Tuple[str, Union[str, bool]]: """ Parse a string to get the subtype @@ -246,7 +246,7 @@ def _parse_subtype(dtype): """ xpr = re.compile(r"Sparse\[(?P[^,]*)(, )?(?P.*?)?\]$") m = xpr.match(dtype) - has_fill_value = False + has_fill_value: Union[str, bool] = False if m: subtype = m.groupdict()["subtype"] has_fill_value = m.groupdict()["fill_value"] or has_fill_value From 59eca823ed04b0fbdfa3c6b775106f74ed79e455 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 27 Nov 2019 21:25:22 +0000 Subject: [PATCH 2/3] update per comments --- pandas/core/arrays/sparse/dtype.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/arrays/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index 735d547dca298..9825b83ca8410 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -1,7 +1,7 @@ """Sparse Dtype""" import re -from typing import Any, Tuple, Union +from typing import Any, Tuple import numpy as np @@ -223,7 +223,7 @@ def construct_from_string(cls, string): raise TypeError(msg) @staticmethod - def _parse_subtype(dtype) -> Tuple[str, Union[str, bool]]: + def _parse_subtype(dtype: str) -> Tuple[str, bool]: """ Parse a string to get the subtype @@ -246,10 +246,10 @@ def _parse_subtype(dtype) -> Tuple[str, Union[str, bool]]: """ xpr = re.compile(r"Sparse\[(?P[^,]*)(, )?(?P.*?)?\]$") m = xpr.match(dtype) - has_fill_value: Union[str, bool] = False + has_fill_value = False if m: subtype = m.groupdict()["subtype"] - has_fill_value = m.groupdict()["fill_value"] or has_fill_value + has_fill_value = bool(m.groupdict()["fill_value"]) or has_fill_value elif dtype == "Sparse": subtype = "float64" else: From 051f90782dd769e4f3d645465c08750f6cceb428 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Wed, 27 Nov 2019 21:54:14 +0000 Subject: [PATCH 3/3] remove redundant code --- pandas/core/arrays/sparse/dtype.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/arrays/sparse/dtype.py b/pandas/core/arrays/sparse/dtype.py index 9825b83ca8410..0124304727ab3 100644 --- a/pandas/core/arrays/sparse/dtype.py +++ b/pandas/core/arrays/sparse/dtype.py @@ -249,7 +249,7 @@ def _parse_subtype(dtype: str) -> Tuple[str, bool]: has_fill_value = False if m: subtype = m.groupdict()["subtype"] - has_fill_value = bool(m.groupdict()["fill_value"]) or has_fill_value + has_fill_value = bool(m.groupdict()["fill_value"]) elif dtype == "Sparse": subtype = "float64" else: