def infer_dtype_from_scalar(val, pandas_dtype=False):
dtype = np.object_<EOL>if isinstance(val, np.ndarray):<EOL><INDENT>msg = "<STR_LIT>"<EOL>if val.ndim != <NUM_LIT:0>:<EOL><INDENT>raise ValueError(msg)<EOL><DEDENT>dtype = val.dtype<EOL>val = val.item()<EOL><DEDENT>elif isinstance(val, str):<EOL><INDENT>dtype = np.object_<EOL><DEDENT>elif isinstance(val, (np.datetime64, datetime)):<EOL><INDENT>val = tslibs.Timestamp(val)<EOL>if val is tslibs.NaT or val.tz is None:<EOL><INDENT>dtype = np.dtype('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>if pandas_dtype:<EOL><INDENT>dtype = DatetimeTZDtype(unit='<STR_LIT>', tz=val.tz)<EOL><DEDENT>else:<EOL><INDENT>return np.object_, val<EOL><DEDENT><DEDENT>val = val.value<EOL><DEDENT>elif isinstance(val, (np.timedelta64, timedelta)):<EOL><INDENT>val = tslibs.Timedelta(val).value<EOL>dtype = np.dtype('<STR_LIT>')<EOL><DEDENT>elif is_bool(val):<EOL><INDENT>dtype = np.bool_<EOL><DEDENT>elif is_integer(val):<EOL><INDENT>if isinstance(val, np.integer):<EOL><INDENT>dtype = type(val)<EOL><DEDENT>else:<EOL><INDENT>dtype = np.int64<EOL><DEDENT><DEDENT>elif is_float(val):<EOL><INDENT>if isinstance(val, np.floating):<EOL><INDENT>dtype = type(val)<EOL><DEDENT>else:<EOL><INDENT>dtype = np.float64<EOL><DEDENT><DEDENT>elif is_complex(val):<EOL><INDENT>dtype = np.complex_<EOL><DEDENT>elif pandas_dtype:<EOL><INDENT>if lib.is_period(val):<EOL><INDENT>dtype = PeriodDtype(freq=val.freq)<EOL>val = val.ordinal<EOL><DEDENT><DEDENT>return dtype, val<EOL>
interpret the dtype from a scalar

Parameters
----------
pandas_dtype : bool, default False
    whether to infer dtype including pandas extension types.
    If False, scalar belongs to pandas extension types is inferred as
    object