parameters: (arg, unit, name, tz, errors: str)
return_statement: return result
docstring: to_datetime specalized to the case where a 'unit' is passed.
docstring_summary: to_datetime specalized to the case where a 'unit' is passed.
docstring_tokens: to_datetime specalized to the case where a unit is passed .
function: def _to_datetime_with_unit(arg, unit, name, tz, errors: str) -> Index:
      """
      to_datetime specalized to the case where a 'unit' is passed.
      """
      arg = getattr(arg, "_values", arg)
  
      # GH#30050 pass an ndarray to tslib.array_with_unit_to_datetime
      # because it expects an ndarray argument
      if isinstance(arg, IntegerArray):
          arr = arg.astype(f"datetime64[{unit}]")
          tz_parsed = None
      else:
          arr, tz_parsed = tslib.array_with_unit_to_datetime(arg, unit, errors=errors)
  
      if errors == "ignore":
          # Index constructor _may_ infer to DatetimeIndex
          result = Index(arr, name=name)
      else:
          result = DatetimeIndex(arr, name=name)
  
      if not isinstance(result, DatetimeIndex):
          return result
  
      # GH#23758: We may still need to localize the result with tz
      # GH#25546: Apply tz_parsed first (from arg), then tz (from caller)
      # result will be naive but in UTC
      result = result.tz_localize("UTC").tz_convert(tz_parsed)
  
      if tz is not None:
          if result.tz is None:
              result = result.tz_localize(tz)
          else:
              result = result.tz_convert(tz)
      return result
function_tokens: def _to_datetime_with_unit ( arg , unit , name , tz , errors : str ) -> Index : arg = getattr ( arg , "_values" , arg ) # GH#30050 pass an ndarray to tslib.array_with_unit_to_datetime # because it expects an ndarray argument if isinstance ( arg , IntegerArray ) : arr = arg . astype ( f"datetime64[{unit}]" ) tz_parsed = None else : arr , tz_parsed = tslib . array_with_unit_to_datetime ( arg , unit , errors = errors ) if errors == "ignore" : # Index constructor _may_ infer to DatetimeIndex result = Index ( arr , name = name ) else : result = DatetimeIndex ( arr , name = name ) if not isinstance ( result , DatetimeIndex ) : return result # GH#23758: We may still need to localize the result with tz # GH#25546: Apply tz_parsed first (from arg), then tz (from caller) # result will be naive but in UTC result = result . tz_localize ( "UTC" ) . tz_convert ( tz_parsed ) if tz is not None : if result . tz is None : result = result . tz_localize ( tz ) else : result = result . tz_convert ( tz ) return result