code: def test_to_numpy_dtype(as_series, unit):
      tz = "US/Eastern"
      obj = pd.DatetimeIndex(["2000", "2001"], tz=tz)
      if as_series:
          obj = Series(obj)
  
      # preserve tz by default
      result = obj.to_numpy()
      expected = np.array(
          [Timestamp("2000", tz=tz), Timestamp("2001", tz=tz)],
          dtype=object,
      )
      tm.assert_numpy_array_equal(result, expected)
  
      result = obj.to_numpy(dtype="object")
      tm.assert_numpy_array_equal(result, expected)
  
      result = obj.to_numpy(dtype="M8[ns]")
      expected = np.array(
          ["2000-01-01T05", "2001-01-01T05"], dtype="M8[ns]"
      )
      tm.assert_numpy_array_equal(result, expected)
  
imports: import numpy
  import pytest
  from pandas.core.dtypes.dtypes import DatetimeTZDtype
  import pandas
  from pandas import CategoricalIndex, Series, Timedelta, Timestamp, date_range
  import pandas._testing
  from pandas.core.arrays import DatetimeArray, IntervalArray, NumpyExtensionArray, PeriodArray, SparseArray, TimedeltaArray
  from pandas.core.arrays.string_arrow import ArrowStringArrayNumpySemantics
label_desc: Use image node_id 8 for calling a global function with example usage: test_to_numpy_dtype(as_series, unit) without return types