code: def nsdiffs(x, test="seas", alpha=0.05, period=1, max_D=1, **kwargs):
      D = 0
      if alpha < 0.01:
          warnings.warn(
              "Specified alpha value is less than the minimum, setting alpha=0.01"
          )
          alpha = 0.01
      elif alpha > 0.1:
          warnings.warn(
              "Specified alpha value is larger than the maximum, setting alpha=0.1"
          )
          alpha = 0.1
      if test == "ocsb":
          warnings.warn(
              "Significance levels other than 5% are not currently supported by test='ocsb', defaulting to alpha = 0.05."
          )
          alpha = 0.05
      if test in ("hegy", "ch"):
          raise NotImplementedError
      if is_constant(x):
          return D
      if period == 1:
          raise ValueError("Non seasonal data")
      elif period < 1:
          warnings.warn(
              "I can't handle data with frequency less than 1. Seasonality will be ignored."
          )
          return 0
      if period >= len(x):
          return 0
  
      def run_tests(x, test, alpha):
          try:
              diff = seas_heuristic(x, period) > 0.64
              if diff not in (0, 1):
                  raise ValueError(f"Found {diff} in seasonal test.")
          except Exception as e:
              warnings.warn(
                  f"The chosen seasonal unit root test encountered an error when testing for the {D} difference.\n"
                  f"From {test}(): {e}\n"
                  f"{D} seasonal differences will be used. Consider using a different unit root test."
              )
              diff = 0
          return diff
  
      dodiff = run_tests(x, test, alpha)
      if dodiff and not isinstance(period, int):
          warnings.warn(
              "The time series frequency has been rounded to support seasonal differencing."
          )
          period = round(period)
      while dodiff and D < max_D:
          D += 1
          x = diff(x, period, 1)
          if is_constant(x):
              return D
          if len(x) >= 2 * period and D < max_D:
              dodiff = run_tests(x, test, alpha)
          else:
              dodiff = False
      return D
  
imports: import math
  import warnings
  from collections import namedtuple
  from functools import partial
  from typing import Optional, Dict, Union, Tuple
  import numpy
  import pandas
  import statsmodels.api
  from numba import njit
  from scipy.optimize import minimize
  from scipy.stats import norm
  from .mstl import mstl
  from .utils import CACHE, NOGIL
label_desc: Use image node_id 33 for calling a global function with example usage: nsdiffs(x, test, alpha, period, max_D) and returns: D, D, int, diff, int, D