Repository: quantopian/zipline
File: zipline/algorithm.py (Python)

Code before:
                # If a DataFrame is passed. Promote it to a Panel.
                # The reader will fake volume values.
                data = pd.Panel({'close': data.copy()})
                data = data.swapaxes(0, 2)

            if isinstance(data, pd.Panel):
                # For compatibility with existing examples allow start/end
                # to be inferred. Start and end have to be midnight UTC.
                if overwrite_sim_params:
                    self.sim_params.period_start = normalize_date(
                        data.major_axis[0].tz_convert('UTC')
                    )
                    self.sim_params.period_end = normalize_date(
                        data.major_axis[-1].tz_convert('UTC')
                    )
                    # Changing period_start and period_close might require
                    # updating of first_open and last_close.
                    self.sim_params.update_internal_from_trading_schedule(
                        trading_schedule=self.trading_schedule
                    )

                    # Assume data is daily if timestamp times are
                    # standardized, otherwise assume minute bars.
                    times = data.major_axis.time
                    if np.all(times == times[0]):
                        self.sim_params.data_frequency = 'daily'
                    else:
                        self.sim_params.data_frequency = 'minute'

                copy_panel = data.rename(
                    # These were the old names for the close/open columns.  We
                    # need to make a copy anyway, so swap these for backwards
                    # compat while we're here.
                    minor_axis={'close_price': 'close', 'open_price': 'open'},
                    copy=True,
                )
                copy_panel.items = self._write_and_map_id_index_to_sids(
                    copy_panel.items, copy_panel.major_axis[0],
                )
                self._assets_from_source = (
                    self.asset_finder.retrieve_all(
                        copy_panel.items
                    )
                )

                if self.sim_params.data_frequency == 'daily':
                    equity_daily_reader = PanelDailyBarReader(
                        self.trading_schedule.all_execution_days,
                        copy_panel,
                    )
                    self.data_portal = DataPortal(

Review comment (suggestion):
edit: nvm about using `pd.infer_freq`, it doesn't handle weekends and holidays unfortunatly.


Code after:
                # If a DataFrame is passed. Promote it to a Panel.
                # The reader will fake volume values.
                data = pd.Panel({'close': data.copy()})
                data = data.swapaxes(0, 2)

            if isinstance(data, pd.Panel):
                # Guard against tz-naive index.
                if data.major_axis.tz is None:
                    data.major_axis = data.major_axis.tz_localize('UTC')

                # For compatibility with existing examples allow start/end
                # to be inferred.
                if overwrite_sim_params:
                    self.sim_params = self.sim_params.create_new(
                        self.trading_calendar.minute_to_session_label(
                            data.major_axis[0]
                        ),
                        self.trading_calendar.minute_to_session_label(
                            data.major_axis[-1]
                        ),
                    )

                    # Assume data is daily if timestamp times are
                    # standardized, otherwise assume minute bars.
                    times = data.major_axis.time
                    if np.all(times == times[0]):
                        self.sim_params.data_frequency = 'daily'
                    else:
                        self.sim_params.data_frequency = 'minute'

                copy_panel = data.rename(
                    # These were the old names for the close/open columns.  We
                    # need to make a copy anyway, so swap these for backwards
                    # compat while we're here.
                    minor_axis={'close_price': 'close', 'open_price': 'open'},
                    copy=True,
                )
                copy_panel.items = self._write_and_map_id_index_to_sids(
                    copy_panel.items, copy_panel.major_axis[0],
                )
                self._assets_from_source = (
                    self.asset_finder.retrieve_all(
                        copy_panel.items
                    )
                )

                if self.sim_params.data_frequency == 'daily':
                    equity_reader_arg = 'equity_daily_reader'
                elif self.sim_params.data_frequency == 'minute':
                    equity_reader_arg = 'equity_minute_reader'
                equity_reader = PanelBarReader(