Repository: pandas-dev/pandas
File: pandas/core/construction.py (Python)

Code before:
    )
    from pandas.core.arrays.string_ import StringDtype

    if lib.is_scalar(data):
        msg = f"Cannot pass scalar '{data}' to 'pandas.array'."
        raise ValueError(msg)
    elif isinstance(data, ABCDataFrame):
        raise TypeError("Cannot pass DataFrame to 'pandas.array'")

    if dtype is None and isinstance(data, (ABCSeries, ABCIndex, ExtensionArray)):
        # Note: we exclude np.ndarray here, will do type inference on it
        dtype = data.dtype

    data = extract_array(data, extract_numpy=True)

    # Handle numpy masked arrays: convert masked values to NA
    # GH#63879
    if isinstance(data, ma.MaskedArray):
        orig_dtype = data.dtype
        na_dtype = ensure_dtype_can_hold_na(data.dtype)
        if hasattr(na_dtype, "char") and na_dtype.char in "SU":
            na_dtype = np.dtype("object")
        filled = cast(ma.MaskedArray, data.astype(na_dtype)).filled(np.nan)
        data = np.asarray(filled)
        if orig_dtype.kind in "iu":
            int_dtype_map = IntegerArray._dtype_cls._get_dtype_mapping()
            if orig_dtype in int_dtype_map:
                return IntegerArray._from_sequence(
                    data, dtype=int_dtype_map[orig_dtype], copy=copy
                )
    # this returns None for not-found dtypes.
    if dtype is not None:
        dtype = pandas_dtype(dtype)

    if isinstance(data, ExtensionArray) and (dtype is None or data.dtype == dtype):
        # e.g. TimedeltaArray[s], avoid casting to NumpyExtensionArray
        if copy:
            return data.copy()
        return data

    if isinstance(dtype, ExtensionDtype):
        cls = dtype.construct_array_type()
        return cls._from_sequence(data, dtype=dtype, copy=copy)

    if dtype is None:
        was_ndarray = isinstance(data, np.ndarray)
        # error: Item "Sequence[object]" of "Sequence[object] | ExtensionArray |
        # ndarray[Any, Any]" has no attribute "dtype"
        if not was_ndarray or data.dtype == object:  # type: ignore[union-attr]
            result = lib.maybe_convert_objects(
                ensure_object(data),

Review comment (suggestion):
It seems to me what you had before was simpler - split of `mask.any()` into two cases: when the mask is all False, just use `asarray`. And when it is true, you have NaNs, so no need to worry about converting integers back.

Code after:
    )
    from pandas.core.arrays.string_ import StringDtype

    if lib.is_scalar(data):
        msg = f"Cannot pass scalar '{data}' to 'pandas.array'."
        raise ValueError(msg)
    elif isinstance(data, ABCDataFrame):
        raise TypeError("Cannot pass DataFrame to 'pandas.array'")

    if dtype is None and isinstance(data, (ABCSeries, ABCIndex, ExtensionArray)):
        # Note: we exclude np.ndarray here, will do type inference on it
        dtype = data.dtype

    data = extract_array(data, extract_numpy=True)

    # Handle numpy masked arrays: convert masked values to NA
    # GH#63879
    if isinstance(data, ma.MaskedArray):
        if data.dtype.names is not None:
            raise ValueError(
                "Cannot construct an array from an ndarray with compound dtype. "
                "Use DataFrame instead."
            )
        elif data.mask is not np.False_ and ma.getmaskarray(data).any():
            na_dtype = ensure_dtype_can_hold_na(data.dtype)
            if na_dtype.char in "SU":
                na_dtype = np.dtype("object")
            data = cast(ma.MaskedArray, data.astype(na_dtype)).filled(np.nan)
        else:
            # No mask, convert to regular array
            data = np.asarray(data)

    # this returns None for not-found dtypes.
    if dtype is not None:
        dtype = pandas_dtype(dtype)

    if isinstance(data, ExtensionArray) and (dtype is None or data.dtype == dtype):
        # e.g. TimedeltaArray[s], avoid casting to NumpyExtensionArray
        if copy:
            return data.copy()
        return data

    if isinstance(dtype, ExtensionDtype):
        cls = dtype.construct_array_type()
        return cls._from_sequence(data, dtype=dtype, copy=copy)

    if dtype is None:
        was_ndarray = isinstance(data, np.ndarray)
        # error: Item "Sequence[object]" of "Sequence[object] | ExtensionArray |
        # ndarray[Any, Any]" has no attribute "dtype"
        if not was_ndarray or data.dtype == object:  # type: ignore[union-attr]