code: def test_instantiation_valid():
      tsa_model.__warningregistry__ = {}
  
      # The primary goal of this test function is to make sure the
      # combinations that are supposed to be valid are actually valid, and
      # that valid but unsupported options give the appropriate warning
      # Secondarily, it also has some tests that invalid combinations raise
      # exceptions, although it's not intended to be comprehensive.
      #
      # Each of `endog`, `exog` can be in the following categories:
      # 0. None (only for exog)
      # 1. list
      # 2. numpy array
      # 3. pandas series
      # 4. pandas dataframe
      #
      # Each pandas index (of `endog`, `exog`, or passed to `dates`) can be:
      # 0. None
      # 1. RangeIndex (if applicable; i.e. if Pandas >= 0.18)
      # 2. Integral Indexes with values exactly equal to 0, 1, ..., nobs-1
      # 3. DatetimeIndex with frequency
      # 4. PeriodIndex with frequency
      # 5. Anything that does not fall into the above categories also should
      #    only raise an exception if it was passed to dates, and may trigger
      #    a warning otherwise.
      #
      # `date` can be one of the following:
      # 0. None
      # 2. Pandas index #2
      # 3. Pandas index #3
      # 4. List of date strings (requires freq)
      # 5. List of datetime objects (requires freq)
      # 6. Array of date strings (requires freq)
      # 7. Array of datetime objects (requires freq)
      # 8. Series of date strings (requires freq)
      # 9. Series of datetime objects (requires freq)
      # 10. Series of pandas timestamps (requires freq)
      # 11. Anything that does not fall into the above categories should raise
      #     an exception.
      #
      # `freq` can be:
      # 0. None
      # 1. Something that can be passed to `pd.to_offset`
      # 2. Anything that cannot should raise an Exception
      #
      # Each test will be denoted by:
      # endog.index:exog.index/date/freq where the corresponding
      # location is the integer from above; e.g. 1.0:0.0/9/1 corresponds to
      # - List endog (with no index)
      # - No exog
      # - Series of datetime objects
      # - Something valid for `pd.to_offset` (e.g. 'D', if that works with
      #   dates)
      #
      # Notice that the endog.index:exog.index really collapses to a single
      # element, which is the evaluated `row_label`. This is first the exog
      # index, if exists, then the endog index, if it exists, or None
      # otherwise. **Thus, we will not test `exog` here.**
      #
      # Example valid combinations of row_label/date/freq include:
      # - */0/0 (i.e. anything is valid if date and freq are not passed)
      # - */%/% where %/% denotes a valid date/freq combination (i.e. any
      #   row_label is valid if a valid date/freq combination is given)
      #
      # Example invalid combinations include:
      # - [1-2],[3-4].4/0/[1-2] (i.e. if have freq, then must have, or
      #   coerce, a date index)
      # - */[4-10]/0 (i.e. for some types of dates, freq must be passed)
  
      # Baseline: list, numpy endog with no dates, no freq
      for endog in dta[:2]:
          # No indexes, should not raise warnings
          with warnings.catch_warnings():
              warnings.simplefilter("error")
  
              mod = tsa_model.TimeSeriesModel(endog)
              assert isinstance(
                  mod._index, pd.RangeIndex
              ) or np.issubdtype(mod._index.dtype, np.integer)
              assert_equal(mod._index_none, True)
              assert_equal(mod._index_dates, False)
              assert_equal(mod._index_generated, True)
              assert_equal(mod.data.dates, None)
              assert_equal(mod.data.freq, None)
  
      # Test list, numpy endog, pandas w/o index; with dates / freq argument
      for endog in dta:
          # Supported date indexes, should not raise warnings, do not need freq
          with warnings.catch_warnings():
              warnings.simplefilter("error")
  
              for ix, freq in date_indexes + period_indexes:
                  mod = tsa_model.TimeSeriesModel(endog, dates=ix)
                  if freq is None:
                      freq = ix.freq
                  if not isinstance(freq, str):
                      freq = ix.freqstr
                  assert_equal(
                      isinstance(
                          mod._index, (pd.DatetimeIndex, pd.PeriodIndex)
                      ),
                      True,
                  )
                  assert_equal(mod._index_none, False)
                  assert_equal(mod._index_dates, True)
                  assert_equal(mod._index_generated, False)
                  assert_equal(mod._index.freq, mod._index_freq)
                  assert_equal(mod.data.dates.equals(mod._index), True)
                  assert_equal(mod.data.freq, freq)
  
          # Supported date indexes, should not raise warnings, can use valid freq
          with warnings.catch_warnings():
              warnings.simplefilter("error")
  
              for ix, freq in date_indexes + period_indexes:
                  mod = tsa_model.TimeSeriesModel(
                      endog, dates=ix, freq=freq
                  )
                  if freq is None:
                      freq = ix.freq
                  if not isinstance(freq, str):
                      freq = ix.freqstr
                  assert_equal(
                      isinstance(
                          mod._index, (pd.DatetimeIndex, pd.PeriodIndex)
                      ),
                      True,
                  )
                  assert_equal(mod._index_none, False)
                  assert_equal(mod._index_dates, True)
                  assert_equal(mod._index_generated, False)
                  assert_equal(mod._index.freq, mod._index_freq)
                  assert_equal(mod.data.dates.equals(mod._index), True)
                  assert_equal(mod.data.freq, freq)
  
          # Other supported indexes, with valid freq, should not raise warnings
          with warnings.catch_warnings():
              warnings.simplefilter("error")
  
              for ix, freq in supported_date_indexes:
                  mod = tsa_model.TimeSeriesModel(
                      endog, dates=ix, freq=freq
                  )
                  if freq is None:
                      freq = ix.freq
                  if not isinstance(freq, str):
                      freq = freq.freqstr
                  assert_equal(
                      isinstance(
                          mod._index, (pd.DatetimeIndex, pd.PeriodIndex)
                      ),
                      True,
                  )
                  assert_equal(mod._index_none, False)
                  assert_equal(mod._index_dates, True)
                  assert_equal(mod._index_generated, False)
                  assert_equal(mod._index.freq, mod._index_freq)
                  assert_equal(mod.data.dates.equals(mod._index), True)
                  assert_equal(mod.data.freq, freq)
  
          # Since only supported indexes are valid `dates` arguments, everything
          # else is invalid here
          for ix, freq in (
              supported_increment_indexes + unsupported_indexes
          ):
              assert_raises(
                  ValueError, tsa_model.TimeSeriesModel, endog, dates=ix
              )
  
      # Test pandas (Series, DataFrame); with index (no dates/freq argument)
      for base_endog in dta[2:4]:
          # DatetimeIndex and PeriodIndex, should not raise warnings
          with warnings.catch_warnings():
              warnings.simplefilter("error")
  
              for ix, freq in date_indexes + period_indexes:
                  endog = base_endog.copy()
                  endog.index = ix
  
                  mod = tsa_model.TimeSeriesModel(endog)
                  if freq is None:
                      freq = ix.freq
                  if not isinstance(freq, str):
                      freq = ix.freqstr
                  assert_equal(
                      isinstance(
                          mod._index, (pd.DatetimeIndex, pd.PeriodIndex)
                      ),
                      True,
                  )
                  assert_equal(mod._index_none, False)
                  assert_equal(mod._index_dates, True)
                  assert_equal(mod._index_generated, False)
                  assert_equal(mod._index.freq, mod._index_freq)
                  assert_equal(mod.data.dates.equals(mod._index), True)
                  assert_equal(mod.data.freq, freq)
  
          # Increment index (this is a "supported" index in the sense that it
          # does not raise a warning, but obviously not a date index)
          endog = base_endog.copy()
          endog.index = supported_increment_indexes[0][0]
  
          mod = tsa_model.TimeSeriesModel(endog)
          assert is_int_index(mod._index)
          assert_equal(mod._index_none, False)
          assert_equal(mod._index_dates, False)
          assert_equal(mod._index_generated, False)
          assert_equal(mod._index_freq, None)
          assert_equal(mod.data.dates, None)
          assert_equal(mod.data.freq, None)
  
          # RangeIndex (start=0, end=nobs, so equivalent to increment index)
          endog = base_endog.copy()
          endog.index = supported_increment_indexes[1][0]
  
          mod = tsa_model.TimeSeriesModel(endog)
          assert type(mod._index) is pd.RangeIndex
          assert not mod._index_none
          assert not mod._index_dates
          assert not mod._index_generated
          assert mod._index_freq is None
          assert mod.data.dates is None
          assert mod.data.freq is None
  
          # Supported indexes *when a freq is given*, should not raise a warning
          with warnings.catch_warnings():
              warnings.simplefilter("error")
  
              for ix, freq in supported_date_indexes:
                  # Avoid warnings due to Series with object dtype
                  if isinstance(ix, pd.Series) and ix.dtype == object:
                      with warnings.catch_warnings():
                          warnings.simplefilter("ignore")
                          endog = pd.DataFrame(base_endog, index=ix)
                  else:
                      endog = pd.DataFrame(base_endog, index=ix)
  
                  mod = tsa_model.TimeSeriesModel(endog, freq=freq)
                  if freq is None:
                      freq = ix.freq
                  if not isinstance(freq, str):
                      freq = freq.freqstr
                  assert_equal(
                      isinstance(
                          mod._index, (pd.DatetimeIndex, pd.PeriodIndex)
                      ),
                      True,
                  )
                  assert_equal(mod._index_none, False)
                  assert_equal(mod._index_dates, True)
                  assert_equal(mod._index_generated, False)
                  assert_equal(mod._index.freq, mod._index_freq)
                  assert_equal(mod.data.dates.equals(mod._index), True)
                  assert_equal(mod.data.freq, freq)
  
          # Unsupported (or any) indexes to the given series, *when a supported
          # date and freq is given*, should not raise a warning
          with warnings.catch_warnings():
              warnings.simplefilter("error")
  
              for ix, freq in supported_date_indexes:
                  endog = base_endog.copy()
                  endog.index = unsupported_indexes[0][0]
  
                  mod = tsa_model.TimeSeriesModel(
                      endog, dates=ix, freq=freq
                  )
                  if freq is None:
                      freq = ix.freq
                  if not isinstance(freq, str):
                      freq = freq.freqstr
                  assert_equal(
                      isinstance(
                          mod._index, (pd.DatetimeIndex, pd.PeriodIndex)
                      ),
                      True,
                  )
                  assert_equal(mod._index_none, False)
                  assert_equal(mod._index_dates, True)
                  assert_equal(mod._index_generated, False)
                  assert_equal(mod._index.freq, mod._index_freq)
                  assert_equal(mod.data.dates.equals(mod._index), True)
                  assert_equal(mod.data.freq, freq)
  
          # Date indexes with inferrable freq, but no given freq, should all give
          # warnings
          message = (
              "No frequency information was provided,"
              " so inferred frequency %s will be used."
          )
          last_len = 0
          with warnings.catch_warnings(record=True) as w:
              warnings.simplefilter("always")
  
              for ix, freq in supported_date_indexes:
                  endog = base_endog.copy()
                  endog.index = ix
                  mod = tsa_model.TimeSeriesModel(endog)
                  if freq is None:
                      freq = ix.freq
                  if not isinstance(freq, str):
                      freq = freq.freqstr
                  assert type(mod._index) is pd.DatetimeIndex
                  assert not mod._index_none
                  assert mod._index_dates
                  assert not mod._index_generated
                  assert_equal(mod._index.freq, mod._index_freq)
                  assert mod.data.dates.equals(mod._index)
  
                  # Note: here, we need to hedge the test a little bit because
                  # inferred frequencies are not always the same as the original
                  # frequency. From the examples above, when the actual freq is
                  # 2QS-OCT, the inferred freq is 2QS-JAN. This is an issue with
                  # inferred frequencies, but since we are warning the user, it's
                  # not a failure of the code. Thus we only test the "major" part
                  # of the freq, and just test that the right message is given
                  # (even though it will not have the actual freq of the data in
                  # it).
                  if len(w) == last_len:
                      continue
                  assert_equal(
                      mod.data.freq.split("-")[0], freq.split("-")[0]
                  )
                  assert_equal(
                      str(w[-1].message), message % mod.data.freq
                  )
                  last_len = len(w)
  
          # Unsupported (but valid) indexes, should all give warnings
          message = (
              "An unsupported index was provided. As a result, forecasts "
              "cannot be generated. To use the model for forecasting, use "
              "on the the supported classes of index."
          )
          with warnings.catch_warnings(record=True) as w:
              warnings.simplefilter("always")
  
              for ix, freq in unsupported_indexes:
                  endog = base_endog.copy()
                  endog.index = ix
                  mod = tsa_model.TimeSeriesModel(endog)
                  assert_equal(
                      isinstance(mod._index, (pd.Index, pd.RangeIndex)),
                      True,
                  )
                  assert_equal(mod._index_none, False)
                  assert_equal(mod._index_dates, False)
                  assert_equal(mod._index_generated, True)
                  assert_equal(mod._index_freq, None)
                  assert_equal(mod.data.dates, None)
                  assert_equal(mod.data.freq, None)
  
                  assert_equal(str(w[0].message), message)
  
          # Date indexes without inferrable freq, and with no given freq, should
          # all give warnings
          message = (
              "A date index has been provided, but it has no"
              " associated frequency information and so will be"
              " ignored when e.g. forecasting."
          )
          with warnings.catch_warnings(record=True) as w:
              warnings.simplefilter("always")
  
              for ix, freq in unsupported_date_indexes:
                  endog = base_endog.copy()
                  endog.index = ix
                  mod = tsa_model.TimeSeriesModel(endog)
                  assert isinstance(
                      mod._index, pd.RangeIndex
                  ) or is_int_index(mod._index)
                  assert_equal(mod._index_none, False)
                  assert_equal(mod._index_dates, False)
                  assert_equal(mod._index_generated, True)
                  assert_equal(mod._index_freq, None)
                  assert_equal(mod.data.dates, None)
                  assert_equal(mod.data.freq, None)
  
                  assert_equal(str(w[0].message), message)
  
      # Test (invalid) freq with no index
      endog = dta[0]
      assert_raises(
          ValueError,
          tsa_model.TimeSeriesModel,
          endog,
          freq=date_indexes[1][0].freq,
      )
  
      # Test conflicting index, freq specifications
      endog = dta[2].copy()
      endog.index = date_indexes[0][0]
      assert_raises(
          ValueError,
          tsa_model.TimeSeriesModel,
          endog,
          freq=date_indexes[1][0].freq,
      )
  
      # Test unsupported index, but a freq specification
      endog = dta[2].copy()
      endog.index = unsupported_indexes[0][0]
      assert_raises(
          ValueError,
          tsa_model.TimeSeriesModel,
          endog,
          freq=date_indexes[1][0].freq,
      )
  
      # Test index that can coerce to date time but incorrect freq
      endog = dta[2].copy()
      endog.index = numpy_datestr_indexes[0][0]
      assert_raises(
          ValueError,
          tsa_model.TimeSeriesModel,
          endog,
          freq=date_indexes[1][0].freq,
      )
  
imports: from statsmodels.compat.pandas import PD_LT_2_2_0, YEAR_END, is_int_index
  import warnings
  import numpy
  from numpy.testing import assert_equal, assert_raises
  import pandas
  import pytest
  from statsmodels.tools.sm_exceptions import ValueWarning
  from statsmodels.tsa.base import tsa_model
label_desc: Use image node_id 1 for calling a global function with example usage: test_instantiation_valid() without return types