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

Code before:
                    # 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(
                        self.asset_finder,
                        self.trading_schedule,
                        first_trading_day=equity_daily_reader
                            .first_trading_day,
                        equity_daily_reader=equity_daily_reader,
                    )
                elif self.sim_params.data_frequency == 'minute':
                    equity_minute_reader = PanelMinuteBarReader(
                        self.trading_schedule.all_execution_days,
                        copy_panel,
                    )
                    self.data_portal = DataPortal(
                        self.asset_finder,
                        self.trading_schedule,
                        first_trading_day=equity_minute_reader
                            .first_trading_day,
                        equity_minute_reader=equity_minute_reader,
                    )

        # Force a reset of the performance tracker, in case
        # this is a repeat run of the algorithm.

Review comment (suggestion):
since the only difference here is the single constructor, we can just conditionally call `PanelDailyBarReader` or `PanelMinuteBarReader` like:

``` python
equity_minute_reader = (
    PanelMinuteBarReader
    if self.sim_params.data_frequency == 'minute' else
    PanelDailyBarReader
)(
    self.trading_schedule.all_execution_days,
    copy_panel,
)
self.data_portal = DataPortal(
    self.asset_finder,
    self.trading_schedule,
    first_trading_day=equity_minute_reader
        .first_trading_day,
    equity_minute_reader=equity_minute_reader,
)
```


Code after:

                    # 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(
                    self.trading_calendar,
                    copy_panel,
                    self.sim_params.data_frequency,
                )

                self.data_portal = DataPortal(
                    self.asset_finder,
                    self.trading_calendar,
                    first_trading_day=equity_reader.first_trading_day,
                    **{equity_reader_arg: equity_reader}
                )

        # Force a reset of the performance tracker, in case
        # this is a repeat run of the algorithm.
        self.perf_tracker = None

        # Create zipline and loop through simulated_trading.
        # Each iteration returns a perf dictionary
        try:
            perfs = []
            for perf in self.get_generator():