diff --git a/pandas/core/dtypes/cast.py b/pandas/core/dtypes/cast.py index eecb1e567bd8f..d4b60ec186b86 100644 --- a/pandas/core/dtypes/cast.py +++ b/pandas/core/dtypes/cast.py @@ -558,7 +558,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False): object """ - dtype = np.object_ + dtype = np.dtype(np.object_) # a 1-element ndarray if isinstance(val, np.ndarray): @@ -577,7 +577,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False): # instead of np.empty (but then you still don't want things # coming out as np.str_! - dtype = np.object_ + dtype = np.dtype(np.object_) elif isinstance(val, (np.datetime64, datetime)): val = tslibs.Timestamp(val) @@ -588,7 +588,7 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False): dtype = DatetimeTZDtype(unit="ns", tz=val.tz) else: # return datetimetz as object - return np.object_, val + return np.dtype(np.object_), val val = val.value elif isinstance(val, (np.timedelta64, timedelta)): @@ -596,22 +596,22 @@ def infer_dtype_from_scalar(val, pandas_dtype: bool = False): dtype = np.dtype("m8[ns]") elif is_bool(val): - dtype = np.bool_ + dtype = np.dtype(np.bool_) elif is_integer(val): if isinstance(val, np.integer): - dtype = type(val) + dtype = np.dtype(type(val)) else: - dtype = np.int64 + dtype = np.dtype(np.int64) elif is_float(val): if isinstance(val, np.floating): - dtype = type(val) + dtype = np.dtype(type(val)) else: - dtype = np.float64 + dtype = np.dtype(np.float64) elif is_complex(val): - dtype = np.complex_ + dtype = np.dtype(np.complex_) elif pandas_dtype: if lib.is_period(val): diff --git a/pandas/core/internals/construction.py b/pandas/core/internals/construction.py index 3a92cfd9bf16d..0856f65306849 100644 --- a/pandas/core/internals/construction.py +++ b/pandas/core/internals/construction.py @@ -233,7 +233,7 @@ def init_dict(data, index, columns, dtype=None): if missing.any() and not is_integer_dtype(dtype): if dtype is None or np.issubdtype(dtype, np.flexible): # GH#1783 - nan_dtype = object + nan_dtype = np.dtype(object) else: nan_dtype = dtype val = construct_1d_arraylike_from_scalar(np.nan, len(index), nan_dtype)