code: def test_iir_stability():
      """Test IIR filter stability check."""
      sig = np.random.RandomState(0).rand(1000)
      sfreq = 1000
      # This will make an unstable filter, should throw RuntimeError
      pytest.raises(
          RuntimeError,
          filter_data,
          sig,
          sfreq,
          0.6,
          None,
          method="iir",
          iir_params=dict(ftype="butter", order=8, output="ba"),
      )
      # These ones should work just fine
      filter_data(
          sig,
          sfreq,
          0.6,
          None,
          method="iir",
          iir_params=dict(ftype="butter", order=8, output="sos"),
      )
      filter_data(
          sig,
          sfreq,
          0.6,
          None,
          method="iir",
          phase="forward",
          iir_params=dict(ftype="butter", order=8, output="sos"),
      )
      # bad system type
      pytest.raises(
          ValueError,
          filter_data,
          sig,
          sfreq,
          0.6,
          None,
          method="iir",
          iir_params=dict(ftype="butter", order=8, output="foo"),
      )
      # missing ftype
      pytest.raises(
          RuntimeError,
          filter_data,
          sig,
          sfreq,
          0.6,
          None,
          method="iir",
          iir_params=dict(order=8, output="sos"),
      )
      # bad ftype
      pytest.raises(
          RuntimeError,
          filter_data,
          sig,
          sfreq,
          0.6,
          None,
          method="iir",
          iir_params=dict(order=8, ftype="foo", output="sos"),
      )
      # missing gstop
      pytest.raises(
          RuntimeError,
          filter_data,
          sig,
          sfreq,
          0.6,
          None,
          method="iir",
          iir_params=dict(gpass=0.5, output="sos"),
      )
      # can't pass iir_params if method='fft'
      pytest.raises(
          ValueError,
          filter_data,
          sig,
          sfreq,
          0.1,
          None,
          method="fft",
          iir_params=dict(ftype="butter", order=2, output="sos"),
      )
      # method must be string
      pytest.raises(
          TypeError, filter_data, sig, sfreq, 0.1, None, method=1
      )
      # unknown method
      pytest.raises(
          ValueError, filter_data, sig, sfreq, 0.1, None, method="blah"
      )
      # bad iir_params
      pytest.raises(
          TypeError,
          filter_data,
          sig,
          sfreq,
          0.1,
          None,
          method="iir",
          iir_params="blah",
      )
      pytest.raises(
          ValueError,
          filter_data,
          sig,
          sfreq,
          0.1,
          None,
          method="fir",
          iir_params=dict(),
      )
  
      # should pass because default trans_bandwidth is not relevant
      iir_params = dict(ftype="butter", order=2, output="sos")
      x_sos = filter_data(
          sig, 250, 0.5, None, method="iir", iir_params=iir_params
      )
      iir_params_sos = construct_iir_filter(
          iir_params, f_pass=0.5, sfreq=250, btype="highpass"
      )
      x_sos_2 = filter_data(
          sig, 250, 0.5, None, method="iir", iir_params=iir_params_sos
      )
      assert_allclose(x_sos[100:-100], x_sos_2[100:-100])
      x_ba = filter_data(
          sig,
          250,
          0.5,
          None,
          method="iir",
          iir_params=dict(ftype="butter", order=2, output="ba"),
      )
      # Note that this will fail for higher orders (e.g., 6) showing the
      # hopefully decreased numerical error of SOS
      assert_allclose(x_sos[100:-100], x_ba[100:-100])
  
imports: import numpy
  import pytest
  from numpy.fft import fft, fftfreq
  from numpy.testing import assert_allclose, assert_almost_equal, assert_array_almost_equal, assert_array_equal, assert_array_less
  from scipy.signal import butter, freqz, sosfreqz
  from scipy.signal import resample
  from mne import Epochs, create_info
  from mne._fiff.pick import _DATA_CH_TYPES_SPLIT
  from mne.filter import _length_factors, _overlap_add_filter, _resample_stim_channels, _smart_pad, construct_iir_filter, create_filter, design_mne_c_filter, detrend, estimate_ringing_samples, filter_data, notch_filter, resample
  from mne.io import RawArray, read_raw_fif
  from mne.utils import catch_logging, requires_mne, run_subprocess, sum_squared
label_desc: Use image node_id 5 for calling a global function with example usage: test_iir_stability() without return types