# Path: intuition/errors.py
# class LoadDataFailed(dna.errors.FactoryError):
#     msg = "Failed to load data for {sids}: {reason}"
# 
# class InvalidDatafeed(dna.errors.FactoryError):
#     msg = "Invalid datafeed setup: {reason}"


import pandas as pd
import dna.logging
import intuition.utils as utils
from datetime import timedelta
from zipline.sources.data_source import DataSource
from zipline.gens.utils import hash_args
from intuition.errors import LoadDataFailed, InvalidDatafeed
        if self._is_live:
            return self.live.mapping
        else:
            return self.backtest.mapping

    def _set_next_tick(self, date):
        ''' Use self.freq and the given date to deduce the next event hour '''
        return date + timedelta(hours=self.frequency)

    def _get_backtest_data(self):
        # The first date is usually a few seconds before now,
        # so we compare to the next one
        if self.backtest and not utils.is_live(self.index[1]):
            try:
                bt_data = self.backtest.get_data(
                    self.sids, self.start, self.end)
            except Exception as error:
                raise LoadDataFailed(sids=self.sids, reason=error)
        else:
            bt_data = None
        return bt_data

    def _agnostic_get_data_at(self, date, data):
        dated_data = pd.DataFrame()
        n_axes = len(data.axes)

        if self._is_live:
            try:
                dated_data = self.live.get_data(self.sids)
            except Exception as error:

# Path: intuition/errors.py
# class LoadDataFailed(dna.errors.FactoryError):
#     msg = "Failed to load data for {sids}: {reason}"
# 
# class InvalidDatafeed(dna.errors.FactoryError):
#     msg = "Invalid datafeed setup: {reason}"


# Path: intuition/api/datafeed.py
import pandas as pd
import dna.logging
import intuition.utils as utils
from datetime import timedelta
from zipline.sources.data_source import DataSource
from zipline.gens.utils import hash_args
from intuition.errors import LoadDataFailed, InvalidDatafeed

        if self._is_live:
            return self.live.mapping
        else:
            return self.backtest.mapping

    def _set_next_tick(self, date):
        ''' Use self.freq and the given date to deduce the next event hour '''
        return date + timedelta(hours=self.frequency)

    def _get_backtest_data(self):
        # The first date is usually a few seconds before now,
        # so we compare to the next one
        if self.backtest and not utils.is_live(self.index[1]):
            try:
                bt_data = self.backtest.get_data(
                    self.sids, self.start, self.end)
            except Exception as error:
                raise LoadDataFailed(sids=self.sids, reason=error)
        else:
            bt_data = None
        return bt_data

    def _agnostic_get_data_at(self, date, data):
        dated_data = pd.DataFrame()
        n_axes = len(data.axes)

        if self._is_live:
            try:
                dated_data = self.live.get_data(self.sids)
            except Exception as error:

                raise LoadDataFailed(sids=self.sids, reason=error)