# Path: yatsm/utils.py
# def date2index(dates, d):
#     """ Returns index of sorted array `dates` containing the date `d`
# 
#     Args:
#       dates (np.ndarray): array of dates (or numbers really) in sorted order
#       d (int, float): number to search for
# 
#     Returns:
#       int: index of `dates` containing value `d`
# 
#     """
#     return np.searchsorted(dates, d, side='right')


import logging
import numpy as np
import numpy.lib.recfunctions as nprf
import scipy.stats
from ..regression.diagnostics import rmse
from ..utils import date2index
    from statsmodels.regression import linear_model
    from statsmodels.stats import diagnostic
        yatsm (YATSM model): fitted YATSM model to check for commission errors
        alpha (float): significance level for F-statistic (default: 0.10)

    Returns:
        np.ndarray: updated copy of ``yatsm.record`` with spurious models
            combined into unified model

    """
    if yatsm.record.size == 1:
        return yatsm.record

    k = yatsm.record[0]['coef'].shape[0]

    # Allocate memory outside of loop
    m_1_rss = np.zeros(yatsm.test_indices.size)
    m_2_rss = np.zeros(yatsm.test_indices.size)
    m_r_rss = np.zeros(yatsm.test_indices.size)

    models = []
    merged = False
    for i in range(len(yatsm.record) - 1):
        if merged:
            m_1 = models[-1]
        else:
            m_1 = yatsm.record[i]
        m_2 = yatsm.record[i + 1]

        # Unrestricted model starts/ends
        m_1_start = date2index(yatsm.dates, m_1['start'])
        m_1_end = date2index(yatsm.dates, m_1['end'])

# Path: yatsm/utils.py
# def date2index(dates, d):
#     """ Returns index of sorted array `dates` containing the date `d`
# 
#     Args:
#       dates (np.ndarray): array of dates (or numbers really) in sorted order
#       d (int, float): number to search for
# 
#     Returns:
#       int: index of `dates` containing value `d`
# 
#     """
#     return np.searchsorted(dates, d, side='right')


# Path: yatsm/algorithms/postprocess.py
import logging
import numpy as np
import numpy.lib.recfunctions as nprf
import scipy.stats
from ..regression.diagnostics import rmse
from ..utils import date2index
    from statsmodels.regression import linear_model
    from statsmodels.stats import diagnostic

        yatsm (YATSM model): fitted YATSM model to check for commission errors
        alpha (float): significance level for F-statistic (default: 0.10)

    Returns:
        np.ndarray: updated copy of ``yatsm.record`` with spurious models
            combined into unified model

    """
    if yatsm.record.size == 1:
        return yatsm.record

    k = yatsm.record[0]['coef'].shape[0]

    # Allocate memory outside of loop
    m_1_rss = np.zeros(yatsm.test_indices.size)
    m_2_rss = np.zeros(yatsm.test_indices.size)
    m_r_rss = np.zeros(yatsm.test_indices.size)

    models = []
    merged = False
    for i in range(len(yatsm.record) - 1):
        if merged:
            m_1 = models[-1]
        else:
            m_1 = yatsm.record[i]
        m_2 = yatsm.record[i + 1]

        # Unrestricted model starts/ends
        m_1_start = date2index(yatsm.dates, m_1['start'])
        m_1_end = date2index(yatsm.dates, m_1['end'])

        m_2_start = date2index(yatsm.dates, m_2['start'])