code: def test_datetime_arrays(datetime_array, engine, pretty):
      value = build_test_dict(datetime_array)
      result = pio.to_json_plotly(value, engine=engine)
  
      def to_str(v):
          try:
              v = v.isoformat(sep="T")
          except (TypeError, AttributeError):
              pass
  
          return str(v)
  
      if isinstance(datetime_array, list):
          dt_values = [to_str(d) for d in datetime_array]
      elif isinstance(datetime_array, pd.Series):
          with warnings.catch_warnings():
              warnings.simplefilter("ignore", FutureWarning)
              # Series.dt.to_pydatetime will return Index[object]
              # https://github.com/pandas-dev/pandas/pull/52459
              dt_values = [
                  to_str(d)
                  for d in np.array(
                      datetime_array.dt.to_pydatetime()
                  ).tolist()
              ]
      elif isinstance(datetime_array, pd.DatetimeIndex):
          dt_values = [
              to_str(d) for d in datetime_array.to_pydatetime().tolist()
          ]
      else:  # numpy datetime64 array
          dt_values = [to_str(d) for d in datetime_array]
  
      array_str = to_json_test(dt_values)
      expected = build_test_dict_string(array_str)
      if orjson:
          # orjson always serializes datetime64 to ns, but json will return either
          # full seconds or microseconds, if the rest is zeros.
          # we don't care about any trailing zeros
          trailing_zeros = re.compile(r'[.]?0+"')
          result = trailing_zeros.sub('"', result)
          expected = trailing_zeros.sub('"', expected)
  
      assert result == expected
      check_roundtrip(result, engine=engine, pretty=pretty)
  
imports: import pytest
  import plotly.io.json
  import plotly.graph_objects
  import plotly.express
  import numpy
  import pandas
  import json
  import datetime
  import re
  import sys
  import warnings
  from pytz import timezone
  from _plotly_utils.optional_imports import get_module
label_desc: Use image node_id 20 for calling a global function with example usage: test_datetime_arrays(datetime_array, engine, pretty) and returns: str