107
107
_int32_max = np .iinfo (np .int32 ).max
108
108
_int64_max = np .iinfo (np .int64 ).max
109
109
110
+ _dtype_obj = np .dtype (object )
111
+
110
112
NumpyArrayT = TypeVar ("NumpyArrayT" , bound = np .ndarray )
111
113
112
114
@@ -123,7 +125,7 @@ def maybe_convert_platform(
123
125
# or ExtensionArray here.
124
126
arr = values
125
127
126
- if arr .dtype == object :
128
+ if arr .dtype == _dtype_obj :
127
129
arr = cast (np .ndarray , arr )
128
130
arr = lib .maybe_convert_objects (arr )
129
131
@@ -159,7 +161,7 @@ def maybe_box_datetimelike(value: Scalar, dtype: Dtype | None = None) -> Scalar:
159
161
-------
160
162
scalar
161
163
"""
162
- if dtype == object :
164
+ if dtype == _dtype_obj :
163
165
pass
164
166
elif isinstance (value , (np .datetime64 , datetime )):
165
167
value = Timestamp (value )
@@ -662,9 +664,7 @@ def _ensure_dtype_type(value, dtype: np.dtype):
662
664
"""
663
665
# Start with exceptions in which we do _not_ cast to numpy types
664
666
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 :
668
668
return value
669
669
670
670
# Note: before we get here we have already excluded isna(value)
@@ -1111,10 +1111,7 @@ def astype_nansafe(
1111
1111
raise ValueError ("dtype must be np.dtype or ExtensionDtype" )
1112
1112
1113
1113
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
1118
1115
):
1119
1116
from pandas .core .construction import ensure_wrapped_if_datetimelike
1120
1117
@@ -1124,7 +1121,7 @@ def astype_nansafe(
1124
1121
if issubclass (dtype .type , str ):
1125
1122
return lib .ensure_string_array (arr , skipna = skipna , convert_na_value = False )
1126
1123
1127
- elif is_datetime64_dtype (arr ):
1124
+ elif is_datetime64_dtype (arr . dtype ):
1128
1125
# Non-overlapping equality check (left operand type: "dtype[Any]", right
1129
1126
# operand type: "Type[signedinteger[Any]]")
1130
1127
if dtype == np .int64 : # type: ignore[comparison-overlap]
@@ -1146,7 +1143,7 @@ def astype_nansafe(
1146
1143
1147
1144
raise TypeError (f"cannot astype a datetimelike from [{ arr .dtype } ] to [{ dtype } ]" )
1148
1145
1149
- elif is_timedelta64_dtype (arr ):
1146
+ elif is_timedelta64_dtype (arr . dtype ):
1150
1147
# error: Non-overlapping equality check (left operand type: "dtype[Any]", right
1151
1148
# operand type: "Type[signedinteger[Any]]")
1152
1149
if dtype == np .int64 : # type: ignore[comparison-overlap]
@@ -1170,7 +1167,7 @@ def astype_nansafe(
1170
1167
elif np .issubdtype (arr .dtype , np .floating ) and np .issubdtype (dtype , np .integer ):
1171
1168
return astype_float_to_int_nansafe (arr , dtype , copy )
1172
1169
1173
- elif is_object_dtype (arr ):
1170
+ elif is_object_dtype (arr . dtype ):
1174
1171
1175
1172
# work around NumPy brokenness, #1987
1176
1173
if np .issubdtype (dtype .type , np .integer ):
@@ -1718,7 +1715,7 @@ def maybe_cast_to_datetime(
1718
1715
# and no coercion specified
1719
1716
value = sanitize_to_nanoseconds (value )
1720
1717
1721
- elif value .dtype == object :
1718
+ elif value .dtype == _dtype_obj :
1722
1719
value = maybe_infer_to_datetimelike (value )
1723
1720
1724
1721
elif isinstance (value , list ):
@@ -1862,9 +1859,7 @@ def construct_2d_arraylike_from_scalar(
1862
1859
1863
1860
if dtype .kind in ["m" , "M" ]:
1864
1861
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 :
1868
1863
if isinstance (value , (np .timedelta64 , np .datetime64 )):
1869
1864
# calling np.array below would cast to pytimedelta/pydatetime
1870
1865
out = np .empty (shape , dtype = object )
@@ -2190,9 +2185,7 @@ def can_hold_element(arr: ArrayLike, element: Any) -> bool:
2190
2185
# ExtensionBlock._can_hold_element
2191
2186
return True
2192
2187
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 :
2196
2189
return True
2197
2190
2198
2191
tipo = maybe_infer_dtype_type (element )
0 commit comments