1515 TYPE_CHECKING ,
1616 Any ,
1717 Sized ,
18+ TypeVar ,
1819 cast ,
1920 overload ,
2021)
107108_int32_max = np .iinfo (np .int32 ).max
108109_int64_max = np .iinfo (np .int64 ).max
109110
111+ NumpyArrayT = TypeVar ("NumpyArrayT" , bound = np .ndarray )
112+
110113
111114def maybe_convert_platform (
112115 values : list | tuple | range | np .ndarray | ExtensionArray ,
@@ -659,7 +662,10 @@ def _ensure_dtype_type(value, dtype: np.dtype):
659662 object
660663 """
661664 # Start with exceptions in which we do _not_ cast to numpy types
662- if dtype == np .object_ :
665+
666+ # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
667+ # operand type: "Type[object_]")
668+ if dtype == np .object_ : # type: ignore[comparison-overlap]
663669 return value
664670
665671 # Note: before we get here we have already excluded isna(value)
@@ -866,10 +872,10 @@ def maybe_infer_dtype_type(element):
866872
867873
868874def maybe_upcast (
869- values : np . ndarray ,
875+ values : NumpyArrayT ,
870876 fill_value : Scalar = np .nan ,
871877 copy : bool = False ,
872- ) -> tuple [np . ndarray , Scalar ]:
878+ ) -> tuple [NumpyArrayT , Scalar ]:
873879 """
874880 Provide explicit type promotion and coercion.
875881
@@ -1093,7 +1099,10 @@ def astype_nansafe(
10931099 raise ValueError ("dtype must be np.dtype or ExtensionDtype" )
10941100
10951101 if arr .dtype .kind in ["m" , "M" ] and (
1096- issubclass (dtype .type , str ) or dtype == object
1102+ issubclass (dtype .type , str )
1103+ # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
1104+ # operand type: "Type[object]")
1105+ or dtype == object # type: ignore[comparison-overlap]
10971106 ):
10981107 from pandas .core .construction import ensure_wrapped_if_datetimelike
10991108
@@ -1104,7 +1113,9 @@ def astype_nansafe(
11041113 return lib .ensure_string_array (arr , skipna = skipna , convert_na_value = False )
11051114
11061115 elif is_datetime64_dtype (arr ):
1107- if dtype == np .int64 :
1116+ # Non-overlapping equality check (left operand type: "dtype[Any]", right
1117+ # operand type: "Type[signedinteger[Any]]")
1118+ if dtype == np .int64 : # type: ignore[comparison-overlap]
11081119 warnings .warn (
11091120 f"casting { arr .dtype } values to int64 with .astype(...) "
11101121 "is deprecated and will raise in a future version. "
@@ -1124,7 +1135,9 @@ def astype_nansafe(
11241135 raise TypeError (f"cannot astype a datetimelike from [{ arr .dtype } ] to [{ dtype } ]" )
11251136
11261137 elif is_timedelta64_dtype (arr ):
1127- if dtype == np .int64 :
1138+ # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
1139+ # operand type: "Type[signedinteger[Any]]")
1140+ if dtype == np .int64 : # type: ignore[comparison-overlap]
11281141 warnings .warn (
11291142 f"casting { arr .dtype } values to int64 with .astype(...) "
11301143 "is deprecated and will raise in a future version. "
@@ -1398,10 +1411,9 @@ def convert_dtypes(
13981411
13991412 if is_string_dtype (inferred_dtype ):
14001413 if not convert_string :
1401- inferred_dtype = input_array .dtype
1414+ return input_array .dtype
14021415 else :
1403- inferred_dtype = pandas_dtype ("string" )
1404- return inferred_dtype
1416+ return pandas_dtype ("string" )
14051417
14061418 if convert_integer :
14071419 target_int_dtype = pandas_dtype ("Int64" )
@@ -1454,7 +1466,9 @@ def convert_dtypes(
14541466 else :
14551467 return input_array .dtype
14561468
1457- return inferred_dtype
1469+ # error: Incompatible return value type (got "Union[str, Union[dtype[Any],
1470+ # ExtensionDtype]]", expected "Union[dtype[Any], ExtensionDtype]")
1471+ return inferred_dtype # type: ignore[return-value]
14581472
14591473
14601474def maybe_infer_to_datetimelike (
@@ -1831,7 +1845,9 @@ def construct_2d_arraylike_from_scalar(
18311845
18321846 if dtype .kind in ["m" , "M" ]:
18331847 value = maybe_unbox_datetimelike_tz_deprecation (value , dtype , stacklevel = 4 )
1834- elif dtype == object :
1848+ # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
1849+ # operand type: "Type[object]")
1850+ elif dtype == object : # type: ignore[comparison-overlap]
18351851 if isinstance (value , (np .timedelta64 , np .datetime64 )):
18361852 # calling np.array below would cast to pytimedelta/pydatetime
18371853 out = np .empty (shape , dtype = object )
@@ -2206,7 +2222,9 @@ def can_hold_element(arr: ArrayLike, element: Any) -> bool:
22062222 return tipo .kind == "b"
22072223 return lib .is_bool (element )
22082224
2209- elif dtype == object :
2225+ # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
2226+ # operand type: "Type[object]")
2227+ elif dtype == object : # type: ignore[comparison-overlap]
22102228 return True
22112229
22122230 elif dtype .kind == "S" :
0 commit comments