From bfc175e2d0859ac020d4d7924803c9397aabceb3 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Wed, 16 Oct 2019 20:11:54 -0400 Subject: [PATCH 01/12] Ignoring some mypy errors related to imports and list inference --- pandas/conftest.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index b032e14d8f7e1..6ff8000832c5a 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -8,7 +8,7 @@ from hypothesis import strategies as st import numpy as np import pytest -from pytz import FixedOffset, utc +from pytz import FixedOffset, utc # type: ignore import pandas.util._test_decorators as td @@ -483,7 +483,7 @@ def tz_aware_fixture(request): UNSIGNED_EA_INT_DTYPES = ["UInt8", "UInt16", "UInt32", "UInt64"] SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"] -ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES +ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES # type: ignore ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES FLOAT_DTYPES = [float, "float32", "float64"] @@ -497,13 +497,13 @@ def tz_aware_fixture(request): BYTES_DTYPES = [bytes, "bytes"] OBJECT_DTYPES = [object, "object"] -ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES +ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES # type: ignore ALL_NUMPY_DTYPES = ( ALL_REAL_DTYPES + COMPLEX_DTYPES + STRING_DTYPES - + DATETIME64_DTYPES - + TIMEDELTA64_DTYPES + + DATETIME64_DTYPES # type: ignore + + TIMEDELTA64_DTYPES # type: ignore + BOOL_DTYPES + OBJECT_DTYPES + BYTES_DTYPES From 64083884e27783296a70160a9a11a5f414171696 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Wed, 16 Oct 2019 21:26:35 -0400 Subject: [PATCH 02/12] Adding Dtype --- pandas/conftest.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 6ff8000832c5a..a699bb1b3e6cd 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -11,6 +11,7 @@ from pytz import FixedOffset, utc # type: ignore import pandas.util._test_decorators as td +from pandas._typing import Dtype import pandas as pd from pandas import DataFrame @@ -481,9 +482,9 @@ def tz_aware_fixture(request): UNSIGNED_INT_DTYPES = ["uint8", "uint16", "uint32", "uint64"] UNSIGNED_EA_INT_DTYPES = ["UInt8", "UInt16", "UInt32", "UInt64"] -SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] +SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] # type: Dtype SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"] -ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES # type: ignore +ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES FLOAT_DTYPES = [float, "float32", "float64"] @@ -497,13 +498,13 @@ def tz_aware_fixture(request): BYTES_DTYPES = [bytes, "bytes"] OBJECT_DTYPES = [object, "object"] -ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES # type: ignore +ALL_REAL_DTYPES = FLOAT_DTYPES + ALL_INT_DTYPES ALL_NUMPY_DTYPES = ( ALL_REAL_DTYPES + COMPLEX_DTYPES + STRING_DTYPES - + DATETIME64_DTYPES # type: ignore - + TIMEDELTA64_DTYPES # type: ignore + + DATETIME64_DTYPES + + TIMEDELTA64_DTYPES + BOOL_DTYPES + OBJECT_DTYPES + BYTES_DTYPES From f4afbb2536c82de2ac40799e13afce267a6893d7 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Wed, 16 Oct 2019 21:27:34 -0400 Subject: [PATCH 03/12] Two spaces --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index a699bb1b3e6cd..152095e684520 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -482,7 +482,7 @@ def tz_aware_fixture(request): UNSIGNED_INT_DTYPES = ["uint8", "uint16", "uint32", "uint64"] UNSIGNED_EA_INT_DTYPES = ["UInt8", "UInt16", "UInt32", "UInt64"] -SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] # type: Dtype +SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] # type: Dtype SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"] ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES From ce2d9b7e50f3207611a0393161670e175c238adf Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Fri, 18 Oct 2019 19:47:44 -0400 Subject: [PATCH 04/12] MR comments --- pandas/_typing.py | 2 +- pandas/conftest.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index 5afe64f719b8a..ecec4e1274d6e 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -18,7 +18,7 @@ AnyArrayLike = TypeVar("AnyArrayLike", "ExtensionArray", "Index", "Series", np.ndarray) ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray) DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta") -Dtype = Union[str, np.dtype, "ExtensionDtype"] +Dtype = Union[str, float, bool, np.dtype, "ExtensionDtype"] FilePathOrBuffer = Union[str, Path, IO[AnyStr]] FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame") diff --git a/pandas/conftest.py b/pandas/conftest.py index 152095e684520..61511d6295fd5 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -2,6 +2,7 @@ from decimal import Decimal import operator import os +from typing import List from dateutil.tz import tzlocal, tzutc import hypothesis @@ -482,14 +483,14 @@ def tz_aware_fixture(request): UNSIGNED_INT_DTYPES = ["uint8", "uint16", "uint32", "uint64"] UNSIGNED_EA_INT_DTYPES = ["UInt8", "UInt16", "UInt32", "UInt64"] -SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] # type: Dtype +SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] # type: List[Dtype] SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"] ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES -FLOAT_DTYPES = [float, "float32", "float64"] -COMPLEX_DTYPES = [complex, "complex64", "complex128"] -STRING_DTYPES = [str, "str", "U"] +FLOAT_DTYPES = [float, "float32", "float64"] # type: List[Dtype] +COMPLEX_DTYPES = [complex, "complex64", "complex128"] # type: List[Dtype] +STRING_DTYPES = [str, "str", "U"] # type: List[Dtype] DATETIME64_DTYPES = ["datetime64[ns]", "M8[ns]"] TIMEDELTA64_DTYPES = ["timedelta64[ns]", "m8[ns]"] From 96a09ecc6c8f7cadfb225d30ee27944b8496a66b Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Fri, 18 Oct 2019 19:48:30 -0400 Subject: [PATCH 05/12] MR comments, removing type ignore --- pandas/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 61511d6295fd5..a168d03dc10cb 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -9,7 +9,7 @@ from hypothesis import strategies as st import numpy as np import pytest -from pytz import FixedOffset, utc # type: ignore +from pytz import FixedOffset, utc import pandas.util._test_decorators as td from pandas._typing import Dtype From f07b7a0cece8fcc3154879066fdf2461ea26dd74 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Fri, 18 Oct 2019 20:21:58 -0400 Subject: [PATCH 06/12] Type Union etc --- pandas/_typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index ecec4e1274d6e..e7ce421b271f7 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -18,7 +18,7 @@ AnyArrayLike = TypeVar("AnyArrayLike", "ExtensionArray", "Index", "Series", np.ndarray) ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray) DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta") -Dtype = Union[str, float, bool, np.dtype, "ExtensionDtype"] +Dtype = Type[Union[str, float, bool, np.dtype, "ExtensionDtype"]] FilePathOrBuffer = Union[str, Path, IO[AnyStr]] FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame") From 77543f267abf1216e529d5862c394938f425b854 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Mon, 21 Oct 2019 10:22:39 -0400 Subject: [PATCH 07/12] Forgot Type --- pandas/_typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index e7ce421b271f7..b169748c966b9 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -1,5 +1,5 @@ from pathlib import Path -from typing import IO, TYPE_CHECKING, AnyStr, Iterable, Optional, TypeVar, Union +from typing import IO, TYPE_CHECKING, AnyStr, Iterable, Optional, TypeVar, Union, Type import numpy as np From 50dadb2929b2f083aaaae575b7f197c28256c856 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Sat, 2 Nov 2019 19:12:46 -0400 Subject: [PATCH 08/12] PR comments --- pandas/_typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index b169748c966b9..9a170d84fc03b 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -18,7 +18,7 @@ AnyArrayLike = TypeVar("AnyArrayLike", "ExtensionArray", "Index", "Series", np.ndarray) ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray) DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta") -Dtype = Type[Union[str, float, bool, np.dtype, "ExtensionDtype"]] +Dtype = Union[ExtensionDtype, Type[Union[str, float, int, complex, bool]]] FilePathOrBuffer = Union[str, Path, IO[AnyStr]] FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame") From 4be05dc65a3c00a1db03a69e5e8629bea01abbf9 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Fri, 13 Dec 2019 15:42:55 -0500 Subject: [PATCH 09/12] PR comments --- pandas/conftest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 070136abd8d42..e3e42bce92969 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -499,14 +499,14 @@ def tz_aware_fixture(request): UNSIGNED_INT_DTYPES = ["uint8", "uint16", "uint32", "uint64"] UNSIGNED_EA_INT_DTYPES = ["UInt8", "UInt16", "UInt32", "UInt64"] -SIGNED_INT_DTYPES = [int, "int8", "int16", "int32", "int64"] # type: List[Dtype] +SIGNED_INT_DTYPES: List[Dtype] = [int, "int8", "int16", "int32", "int64"] SIGNED_EA_INT_DTYPES = ["Int8", "Int16", "Int32", "Int64"] ALL_INT_DTYPES = UNSIGNED_INT_DTYPES + SIGNED_INT_DTYPES ALL_EA_INT_DTYPES = UNSIGNED_EA_INT_DTYPES + SIGNED_EA_INT_DTYPES -FLOAT_DTYPES = [float, "float32", "float64"] # type: List[Dtype] -COMPLEX_DTYPES = [complex, "complex64", "complex128"] # type: List[Dtype] -STRING_DTYPES = [str, "str", "U"] # type: List[Dtype] +FLOAT_DTYPES: List[Dtype] = [float, "float32", "float64"] +COMPLEX_DTYPES: List[Dtype] = [complex, "complex64", "complex128"] +STRING_DTYPES: List[Dtype] = [str, "str", "U"] DATETIME64_DTYPES = ["datetime64[ns]", "M8[ns]"] TIMEDELTA64_DTYPES = ["timedelta64[ns]", "m8[ns]"] From 3fbf980355c9e9f0f02119bc823b3297332562d6 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Sun, 29 Dec 2019 15:33:58 +0100 Subject: [PATCH 10/12] Update pandas/_typing.py Co-Authored-By: William Ayd --- pandas/_typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index e13fc5ef1cbe2..1968c33ae4a0c 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -29,7 +29,7 @@ AnyArrayLike = TypeVar("AnyArrayLike", "ExtensionArray", "Index", "Series", np.ndarray) ArrayLike = TypeVar("ArrayLike", "ExtensionArray", np.ndarray) DatetimeLikeScalar = TypeVar("DatetimeLikeScalar", "Period", "Timestamp", "Timedelta") -Dtype = Union[ExtensionDtype, Type[Union[str, float, int, complex, bool]]] +Dtype = Union["ExtensionDtype", Type[Union[str, float, int, complex, bool]]] FilePathOrBuffer = Union[str, Path, IO[AnyStr]] FrameOrSeries = TypeVar("FrameOrSeries", bound="NDFrame") From 4b8b56551309024dcea9c09831f24bfebca7b77c Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Thu, 16 Jan 2020 18:55:54 -0500 Subject: [PATCH 11/12] Fixing import sort order --- pandas/_typing.py | 2 +- pandas/conftest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index a74ded8e4f685..7f50a321f56f7 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -11,9 +11,9 @@ List, Mapping, Optional, + Type, TypeVar, Union, - Type, ) import numpy as np diff --git a/pandas/conftest.py b/pandas/conftest.py index 2bc23ceffe961..fa6c894b19da0 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -12,8 +12,8 @@ import pytest from pytz import FixedOffset, utc -import pandas.util._test_decorators as td from pandas._typing import Dtype +import pandas.util._test_decorators as td import pandas as pd from pandas import DataFrame From dd279e94bcd2a5a639170908d41aab8c369ffba6 Mon Sep 17 00:00:00 2001 From: Angela Ambroz Date: Wed, 25 Mar 2020 14:36:03 -0400 Subject: [PATCH 12/12] Linting --- pandas/_typing.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/_typing.py b/pandas/_typing.py index d89723ff534f8..e1b6a5e2e6876 100644 --- a/pandas/_typing.py +++ b/pandas/_typing.py @@ -45,7 +45,9 @@ # other -Dtype = Union["ExtensionDtype", str, np.dtype, Type[Union[str, float, int, complex, bool]]] +Dtype = Union[ + "ExtensionDtype", str, np.dtype, Type[Union[str, float, int, complex, bool]] +] DtypeObj = Union[np.dtype, "ExtensionDtype"] FilePathOrBuffer = Union[str, Path, IO[AnyStr]]