'Use a history window with non-monotonically increasing dates.
A scenario which does not occur during simulations, but useful
for using a history loader in a notebook.'

def test_history_window_out_of_order_dates(self):

    window_1 = self.data_portal.get_history_window([self.ASSET1], pd.Timestamp('2014-02-07', tz='UTC'), 4, '1d', 'close', 'daily')
    window_2 = self.data_portal.get_history_window([self.ASSET1], pd.Timestamp('2014-02-05', tz='UTC'), 4, '1d', 'close', 'daily')
    window_3 = self.data_portal.get_history_window([self.ASSET1], pd.Timestamp('2014-02-07', tz='UTC'), 4, '1d', 'close', 'daily')
    window_4 = self.data_portal.get_history_window([self.ASSET1], pd.Timestamp('2014-01-22', tz='UTC'), 4, '1d', 'close', 'daily')
    np.testing.assert_almost_equal(window_1.values, window_3.values)
    offsets = np.arange(4)
    def assert_window_prices(window, prices):
        np.testing.assert_almost_equal(window.loc[:, self.ASSET1], prices)
    assert_window_prices(window_1, (23 + offsets))
    assert_window_prices(window_2, (21 + offsets))
    assert_window_prices(window_3, (23 + offsets))
    if (not self.trading_calendar.is_session('2014-01-20')):
        assert_window_prices(window_4, (11 + offsets))
    else:
        assert_window_prices(window_4, [12, nan, 13, 14])
