code: def maybe_upcast_putmask(result, mask, other):
      """
      A safe version of putmask that potentially upcasts the result
  
      Parameters
      ----------
      result : ndarray
          The destination array. This will be mutated in-place if no upcasting is
          necessary.
      mask : boolean ndarray
      other : ndarray or scalar
          The source array or value
  
      Returns
      -------
      result : ndarray
      changed : boolean
          Set to true if the result array was upcasted
      """
  
      if mask.any():
          # Two conversions for date-like dtypes that can't be done automatically
          # in np.place:
          #   NaN -> NaT
          #   integer or integer array -> date-like array
          if is_datetimelike(result.dtype):
              if is_scalar(other):
                  if isna(other):
                      other = result.dtype.type("nat")
                  elif is_integer(other):
                      other = np.array(other, dtype=result.dtype)
              elif is_integer_dtype(other):
                  other = np.array(other, dtype=result.dtype)
  
          def changeit():
              # try to directly set by expanding our array to full
              # length of the boolean
              try:
                  om = other[mask]
                  om_at = om.astype(result.dtype)
                  if (om == om_at).all():
                      new_result = result.values.copy()
                      new_result[mask] = om_at
                      result[:] = new_result
                      return result, False
              except Exception:
                  pass
  
              # we are forced to change the dtype of the result as the input
              # isn't compatible
              r, _ = maybe_upcast(result, fill_value=other, copy=True)
              np.place(r, mask, other)
  
              return r, True
  
          # we want to decide whether place will work
          # if we have nans in the False portion of our mask then we need to
          # upcast (possibly), otherwise we DON't want to upcast (e.g. if we
          # have values, say integers, in the success portion then it's ok to not
          # upcast)
          new_dtype, _ = maybe_promote(result.dtype, other)
          if new_dtype != result.dtype:
              # we have a scalar or len 0 ndarray
              # and its nan and we are changing some values
              if is_scalar(other) or (
                  isinstance(other, np.ndarray) and other.ndim < 1
              ):
                  if isna(other):
                      return changeit()
  
              # we have an ndarray and the masking has nans in it
              else:
                  if isna(other[mask]).any():
                      return changeit()
  
          try:
              np.place(result, mask, other)
          except Exception:
              return changeit()
  
      return result, False
  
imports: from datetime import datetime, timedelta
  import numpy
  from pandas._libs import lib, tslib, tslibs
  from pandas._libs.tslibs import NaT, OutOfBoundsDatetime, Period, iNaT
  from pandas.compat import PY3, string_types, text_type, to_str
  from .common import _INT64_DTYPE, _NS_DTYPE, _POSSIBLY_CAST_DTYPES, _TD_DTYPE, ensure_int8, ensure_int16, ensure_int32, ensure_int64, ensure_object, is_bool, is_bool_dtype, is_categorical_dtype, is_complex, is_complex_dtype, is_datetime64_dtype, is_datetime64_ns_dtype, is_datetime64tz_dtype, is_datetime_or_timedelta_dtype, is_datetimelike, is_dtype_equal, is_extension_array_dtype, is_extension_type, is_float, is_float_dtype, is_integer, is_integer_dtype, is_object_dtype, is_scalar, is_string_dtype, is_timedelta64_dtype, is_timedelta64_ns_dtype, is_unsigned_integer_dtype, pandas_dtype
  from .dtypes import DatetimeTZDtype, ExtensionDtype, PandasExtensionDtype, PeriodDtype
  from .generic import ABCDatetimeArray, ABCDatetimeIndex, ABCPeriodArray, ABCPeriodIndex, ABCSeries
  from .inference import is_list_like
  from .missing import isna, notna
label_desc: Use image node_id 4 for calling a global function with example usage: maybe_upcast_putmask(result, mask, other) and returns: result,  False, r,  True, changeit, result,  False, changeit, changeit