code: def test_trials_dataframe(
      storage_mode: str, attrs: tuple[str, ...], multi_index: bool
  ) -> None:
      def f(trial: Trial) -> float:
          x = trial.suggest_int("x", 1, 1)
          y = trial.suggest_categorical("y", (2.5,))
          trial.set_user_attr("train_loss", 3)
          trial.storage.set_trial_system_attr(
              trial._trial_id, "foo", "bar"
          )
          value = x + y  # 3.5
  
          # Test reported intermediate values, although it in practice is not "intermediate".
          trial.report(value, step=0)
  
          return value
  
      with StorageSupplier(storage_mode) as storage:
          study = create_study(storage=storage)
          study.optimize(f, n_trials=3)
          df = study.trials_dataframe(
              attrs=attrs, multi_index=multi_index
          )
          # Change index to access rows via trial number.
          if multi_index:
              df.set_index(("number", ""), inplace=True, drop=False)
          else:
              df.set_index("number", inplace=True, drop=False)
          assert len(df) == 3
  
          # Number columns are as follows (total of 13):
          #   non-nested: 6 (number, value, state, datetime_start, datetime_complete, duration)
          #   params: 2
          #   distributions: 2
          #   user_attrs: 1
          #   system_attrs: 1
          #   intermediate_values: 1
          expected_n_columns = len(attrs)
          if "params" in attrs:
              expected_n_columns += 1
          if "distributions" in attrs:
              expected_n_columns += 1
          assert len(df.columns) == expected_n_columns
  
          for i in range(3):
              assert df.number[i] == i
              assert df.state[i] == "COMPLETE"
              assert df.value[i] == 3.5
              assert isinstance(df.datetime_start[i], pd.Timestamp)
              assert isinstance(df.datetime_complete[i], pd.Timestamp)
  
              if multi_index:
                  if "distributions" in attrs:
                      assert ("distributions", "x") in df.columns
                      assert ("distributions", "y") in df.columns
                  if "_trial_id" in attrs:
                      assert (
                          "trial_id",
                          "",
                      ) in df.columns  # trial_id depends on other tests.
                  if "duration" in attrs:
                      assert ("duration", "") in df.columns
  
                  assert df.params.x[i] == 1
                  assert df.params.y[i] == 2.5
                  assert df.user_attrs.train_loss[i] == 3
                  assert df.system_attrs.foo[i] == "bar"
              else:
                  if "distributions" in attrs:
                      assert "distributions_x" in df.columns
                      assert "distributions_y" in df.columns
                  if "_trial_id" in attrs:
                      assert (
                          "trial_id" in df.columns
                      )  # trial_id depends on other tests.
                  if "duration" in attrs:
                      assert "duration" in df.columns
  
                  assert df.params_x[i] == 1
                  assert df.params_y[i] == 2.5
                  assert df.user_attrs_train_loss[i] == 3
                  assert df.system_attrs_foo[i] == "bar"
  
file_path: optuna/tests/study_tests/test_dataframe.py
imports: from __future__ import annotations
  import pandas
  import pytest
  from optuna import create_study
  from optuna import create_trial
  from optuna import Trial
  from optuna.testing.storages import STORAGE_MODES
  from optuna.testing.storages import StorageSupplier
  from optuna.trial import TrialState
label_desc: Use image node_id 2 for calling a global function with example usage: test_trials_dataframe(storage_mode, attrs, multi_index) and returns: value