107107_int32_max = np .iinfo (np .int32 ).max
108108_int64_max = np .iinfo (np .int64 ).max
109109
110+ _dtype_obj = np .dtype (object )
111+
110112NumpyArrayT = TypeVar ("NumpyArrayT" , bound = np .ndarray )
111113
112114
@@ -123,7 +125,7 @@ def maybe_convert_platform(
123125 # or ExtensionArray here.
124126 arr = values
125127
126- if arr .dtype == object :
128+ if arr .dtype == _dtype_obj :
127129 arr = cast (np .ndarray , arr )
128130 arr = lib .maybe_convert_objects (arr )
129131
@@ -159,7 +161,7 @@ def maybe_box_datetimelike(value: Scalar, dtype: Dtype | None = None) -> Scalar:
159161 -------
160162 scalar
161163 """
162- if dtype == object :
164+ if dtype == _dtype_obj :
163165 pass
164166 elif isinstance (value , (np .datetime64 , datetime )):
165167 value = Timestamp (value )
@@ -662,9 +664,7 @@ def _ensure_dtype_type(value, dtype: np.dtype):
662664 """
663665 # Start with exceptions in which we do _not_ cast to numpy types
664666
665- # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
666- # operand type: "Type[object_]")
667- if dtype == np .object_ : # type: ignore[comparison-overlap]
667+ if dtype == _dtype_obj :
668668 return value
669669
670670 # Note: before we get here we have already excluded isna(value)
@@ -1111,10 +1111,7 @@ def astype_nansafe(
11111111 raise ValueError ("dtype must be np.dtype or ExtensionDtype" )
11121112
11131113 if arr .dtype .kind in ["m" , "M" ] and (
1114- issubclass (dtype .type , str )
1115- # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
1116- # operand type: "Type[object]")
1117- or dtype == object # type: ignore[comparison-overlap]
1114+ issubclass (dtype .type , str ) or dtype == _dtype_obj
11181115 ):
11191116 from pandas .core .construction import ensure_wrapped_if_datetimelike
11201117
@@ -1124,7 +1121,7 @@ def astype_nansafe(
11241121 if issubclass (dtype .type , str ):
11251122 return lib .ensure_string_array (arr , skipna = skipna , convert_na_value = False )
11261123
1127- elif is_datetime64_dtype (arr ):
1124+ elif is_datetime64_dtype (arr . dtype ):
11281125 # Non-overlapping equality check (left operand type: "dtype[Any]", right
11291126 # operand type: "Type[signedinteger[Any]]")
11301127 if dtype == np .int64 : # type: ignore[comparison-overlap]
@@ -1146,7 +1143,7 @@ def astype_nansafe(
11461143
11471144 raise TypeError (f"cannot astype a datetimelike from [{ arr .dtype } ] to [{ dtype } ]" )
11481145
1149- elif is_timedelta64_dtype (arr ):
1146+ elif is_timedelta64_dtype (arr . dtype ):
11501147 # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
11511148 # operand type: "Type[signedinteger[Any]]")
11521149 if dtype == np .int64 : # type: ignore[comparison-overlap]
@@ -1170,7 +1167,7 @@ def astype_nansafe(
11701167 elif np .issubdtype (arr .dtype , np .floating ) and np .issubdtype (dtype , np .integer ):
11711168 return astype_float_to_int_nansafe (arr , dtype , copy )
11721169
1173- elif is_object_dtype (arr ):
1170+ elif is_object_dtype (arr . dtype ):
11741171
11751172 # work around NumPy brokenness, #1987
11761173 if np .issubdtype (dtype .type , np .integer ):
@@ -1718,7 +1715,7 @@ def maybe_cast_to_datetime(
17181715 # and no coercion specified
17191716 value = sanitize_to_nanoseconds (value )
17201717
1721- elif value .dtype == object :
1718+ elif value .dtype == _dtype_obj :
17221719 value = maybe_infer_to_datetimelike (value )
17231720
17241721 elif isinstance (value , list ):
@@ -1862,9 +1859,7 @@ def construct_2d_arraylike_from_scalar(
18621859
18631860 if dtype .kind in ["m" , "M" ]:
18641861 value = maybe_unbox_datetimelike_tz_deprecation (value , dtype )
1865- # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
1866- # operand type: "Type[object]")
1867- elif dtype == object : # type: ignore[comparison-overlap]
1862+ elif dtype == _dtype_obj :
18681863 if isinstance (value , (np .timedelta64 , np .datetime64 )):
18691864 # calling np.array below would cast to pytimedelta/pydatetime
18701865 out = np .empty (shape , dtype = object )
@@ -2190,9 +2185,7 @@ def can_hold_element(arr: ArrayLike, element: Any) -> bool:
21902185 # ExtensionBlock._can_hold_element
21912186 return True
21922187
2193- # error: Non-overlapping equality check (left operand type: "dtype[Any]", right
2194- # operand type: "Type[object]")
2195- if dtype == object : # type: ignore[comparison-overlap]
2188+ if dtype == _dtype_obj :
21962189 return True
21972190
21982191 tipo = maybe_infer_dtype_type (element )
0 commit comments