code: def ljungbox_autocorrelation(
      data: pd.Series,
      n_lags: Optional[int] = None,
      confidence_level: float = 0.05,
  ) -> TestResult:
      """Null hypothesis - no auto correlation amounts specified lags.
  
      Args:
          data (pd.Series): Time series.
          n_lags (int): Number of lags, if not supplied calculated as ``10*log(data.length)``.
          confidence_level (float): Confidence level for rejecting the null hypothesis.
  
      Returns:
          TestResult: test name, p-value, null hypothesis, reject?, confidence level and details.
  
      See Also:
          https://www.statsmodels.org/stable/generated/statsmodels.tsa.stattools.acf.html
      """
      ser_clean = data
      if np.isnan(data).any():
          ser_clean = data.dropna()
          warnings.warn("Found and removed N/A values.", UserWarning)
  
      if not n_lags:
          n_lags = math.ceil(math.log(len(ser_clean), 10) * 10)
          # n_lags needs to be less than array"s len -> edge case, small arrays
          n_lags = min(n_lags, len(ser_clean) - 1)
  
      acf_result, confidence_interval, q_stat, p_value = acf(
          ser_clean,
          nlags=n_lags,
          fft=False,
          qstat=True,
          alpha=confidence_level,
      )
      outcome_specifics = {
          "acf": acf_result.tolist(),
          "confidence_interval": confidence_interval.tolist(),
          "q_stat": q_stat.tolist(),
          "p_values": p_value.tolist(),
      }
      reject_h0 = bool(min(p_value) < confidence_level)
      result = TestResult(
          test="Ljung-Box",
          p_value=min(p_value),
          null_hypothesis=f"No autocorrelation among specified lag({n_lags})",
          reject_null_hypothesis=reject_h0,
          details=outcome_specifics,
          confidence_level=confidence_level,
      )
  
      return result
  
file_path: tslumen/tslumen/profile/stat_tests.py
imports: from typing import Dict, Any, Optional
  from dataclasses import dataclass
  import math
  import warnings
  import numpy
  import pandas
  import scipy
  import statsmodels.stats.api
  from statsmodels.tsa.tsatools import freq_to_period
  from statsmodels.tsa.stattools import acf, adfuller, kpss
  from tslumen.profile.base import ProfilingFunction, _DCDict
  from tslumen.misc import repr_html
label_desc: Use image node_id 2 for calling a global function with example usage: ljungbox_autocorrelation(data, n_lags, confidence_level) and returns: result