From b91d11ac6bf029b6fed40e946fdcfb0dafdc6753 Mon Sep 17 00:00:00 2001 From: Alistair Date: Fri, 22 Oct 2021 14:26:35 +0100 Subject: [PATCH 1/4] Attempt to fix CI --- pandas/core/dtypes/cast.py | 4 ++-- pandas/tests/indexes/test_engines.py | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 408e58e23aaed..46bb5841b5fe2 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -910,9 +910,9 @@ def maybe_upcast( """ new_dtype, fill_value = maybe_promote(values.dtype, fill_value) # We get a copy in all cases _except_ (values.dtype == new_dtype and not copy) - values = values.astype(new_dtype, copy=copy) + upcast_values = values.astype(new_dtype, copy=copy) - return values, fill_value + return upcast_values, fill_value def invalidate_string_dtypes(dtype_set: set[DtypeObj]): diff --git a/pandas/tests/indexes/test_engines.py b/pandas/tests/indexes/test_engines.py index 663ba7332c864..2ce52933c9823 100644 --- a/pandas/tests/indexes/test_engines.py +++ b/pandas/tests/indexes/test_engines.py @@ -59,11 +59,7 @@ class TestTimedeltaEngine: [ # error: Argument 1 to "Timestamp" has incompatible type "timedelta64"; # expected "Union[integer[Any], float, str, date, datetime64]" - pd.Timestamp( - pd.Timedelta(days=42).asm8.view( - "datetime64[ns]" - ) # type: ignore[arg-type] - ), + pd.Timestamp(pd.Timedelta(days=42).asm8.view("datetime64[ns]")), pd.Timedelta(days=42).value, pd.Timedelta(days=42).to_pytimedelta(), pd.Timedelta(days=42).to_timedelta64(), From 27775378632e588dfccd8ca86d56becf7e348612 Mon Sep 17 00:00:00 2001 From: Alistair Date: Fri, 22 Oct 2021 14:37:26 +0100 Subject: [PATCH 2/4] Remove comment --- pandas/tests/indexes/test_engines.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/tests/indexes/test_engines.py b/pandas/tests/indexes/test_engines.py index 2ce52933c9823..02d8c5b2a6a22 100644 --- a/pandas/tests/indexes/test_engines.py +++ b/pandas/tests/indexes/test_engines.py @@ -57,8 +57,6 @@ class TestTimedeltaEngine: @pytest.mark.parametrize( "scalar", [ - # error: Argument 1 to "Timestamp" has incompatible type "timedelta64"; - # expected "Union[integer[Any], float, str, date, datetime64]" pd.Timestamp(pd.Timedelta(days=42).asm8.view("datetime64[ns]")), pd.Timedelta(days=42).value, pd.Timedelta(days=42).to_pytimedelta(), From 81227d839a965b54a47e937586b1f9fa9821c3ad Mon Sep 17 00:00:00 2001 From: Alistair Date: Fri, 22 Oct 2021 16:06:00 +0100 Subject: [PATCH 3/4] Reflect the fact type of values can change --- pandas/core/dtypes/cast.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index 46bb5841b5fe2..a1359fc2266c4 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -15,7 +15,6 @@ TYPE_CHECKING, Any, Sized, - TypeVar, cast, overload, ) @@ -107,8 +106,6 @@ _int32_max = np.iinfo(np.int32).max _int64_max = np.iinfo(np.int64).max -NumpyArrayT = TypeVar("NumpyArrayT", bound=np.ndarray) - def maybe_convert_platform( values: list | tuple | range | np.ndarray | ExtensionArray, @@ -886,10 +883,10 @@ def maybe_infer_dtype_type(element): def maybe_upcast( - values: NumpyArrayT, + values: np.ndarray, fill_value: Scalar = np.nan, copy: bool = False, -) -> tuple[NumpyArrayT, Scalar]: +) -> tuple[np.ndarray, Scalar]: """ Provide explicit type promotion and coercion. From 1ca9aaf12c7d6711b4df65ffecded9e075838f37 Mon Sep 17 00:00:00 2001 From: Alistair Date: Fri, 22 Oct 2021 17:16:25 +0100 Subject: [PATCH 4/4] Just ignore for now.. --- pandas/core/dtypes/cast.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index a1359fc2266c4..db3d764fb97a2 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -15,6 +15,7 @@ TYPE_CHECKING, Any, Sized, + TypeVar, cast, overload, ) @@ -106,6 +107,8 @@ _int32_max = np.iinfo(np.int32).max _int64_max = np.iinfo(np.int64).max +NumpyArrayT = TypeVar("NumpyArrayT", bound=np.ndarray) + def maybe_convert_platform( values: list | tuple | range | np.ndarray | ExtensionArray, @@ -883,10 +886,10 @@ def maybe_infer_dtype_type(element): def maybe_upcast( - values: np.ndarray, + values: NumpyArrayT, fill_value: Scalar = np.nan, copy: bool = False, -) -> tuple[np.ndarray, Scalar]: +) -> tuple[NumpyArrayT, Scalar]: """ Provide explicit type promotion and coercion. @@ -909,7 +912,7 @@ def maybe_upcast( # We get a copy in all cases _except_ (values.dtype == new_dtype and not copy) upcast_values = values.astype(new_dtype, copy=copy) - return upcast_values, fill_value + return upcast_values, fill_value # type: ignore[return-value] def invalidate_string_dtypes(dtype_set: set[DtypeObj]):