code: def nsdiffs(x, m, max_D=2, test="ocsb", **kwargs):
      """Estimate the seasonal differencing term, ``D``.
  
      Perform a test of seasonality for different levels of ``D`` to
      estimate the number of seasonal differences required to make a given time
      series stationary. Will select the maximum value of ``D`` for which
      the time series is judged seasonally stationary by the statistical test.
  
      Parameters
      ----------
      x : array-like, shape=(n_samples, [n_features])
          The array to difference.
  
      m : int
          The number of seasonal periods (i.e., frequency of the
          time series)
  
      max_D : int, optional (default=2)
          Maximum number of seasonal differences allowed. Must
          be a positive integer. The estimated value of ``D`` will not
          exceed ``max_D``.
  
      test : str, optional (default='ocsb')
          Type of unit root test of seasonality to use in order
          to detect seasonal periodicity. Valid tests include ("ocsb", "ch").
          Note that the CHTest is very slow for large data.
  
      Returns
      -------
      D : int
          The estimated seasonal differencing term. This is the maximum value
          of ``D`` such that ``D <= max_D`` and the time series is judged
          seasonally stationary. If the time series is constant, will return 0.
      """
      if max_D <= 0:
          raise ValueError("max_D must be a positive integer")
  
      # get the test - this validates m internally
      testfunc = get_callable(test, VALID_STESTS)(
          m, **kwargs
      ).estimate_seasonal_differencing_term
      x = check_endog(x, dtype=DTYPE, copy=False)
  
      if is_constant(x):
          return 0
  
      D = 0
      dodiff = testfunc(x)
      while dodiff == 1 and D < max_D:
          D += 1
          x = diff(x, lag=m)
  
          if is_constant(x):
              return D
  
          # Issue 351: if the differenced array is now shorter than the seasonal
          # periodicity, we need to bail out now.
          if len(x) < m:
              warnings.warn(
                  "Appropriate D value may not have been reached; "
                  "length of seasonally-differenced array (%i) is "
                  "shorter than m (%i). Using D=%i" % (len(x), m, D)
              )
              return D
  
          dodiff = testfunc(x)
  
      return D
  
file_path: pmdarima/pmdarima/arima/utils.py
imports: from sklearn.utils.validation import column_or_1d
  import numpy
  import warnings
  from ..None import context_managers
  from ..utils import get_callable
  from ..utils.array import diff, check_endog
  from ..compat.numpy import DTYPE
  from .None import stationarity
  from .None import seasonality
label_desc: Use image node_id 2 for calling a global function with example usage: nsdiffs(x, m, max_D, test) and returns: D, int, D, D