class_docstr: Class capable of writing daily OHLCV data to disk in a format that can
  be read efficiently by BcolzDailyOHLCVReader.
  
  Parameters
  ----------
  filename : str
      The location at which we should write our output.
  calendar : zipline.utils.calendar.trading_calendar
      Calendar to use to compute asset calendar offsets.
  start_session: pd.Timestamp
      Midnight UTC session label.
  end_session: pd.Timestamp
      Midnight UTC session label.
  
  See Also
  --------
  zipline.data.bcolz_daily_bars.BcolzDailyBarReader
class_docstr_tok: ["Class","capable","of","writing","daily","OHLCV","data","to","disk","in","a","format","that","can","be","read","efficiently","by","BcolzDailyOHLCVReader",".","Parameters","--","--","--","--","--","filename",":","str","The","location","at","which","we","should","write","our","output",".","calendar",":","zipline.utils.calendar.trading_calendar","Calendar","to","use","to","compute","asset","calendar","offsets",".","start_session",":","pd.Timestamp","Midnight","UTC","session","label",".","end_session",":","pd.Timestamp","Midnight","UTC","session","label",".","See","Also","--","--","--","--","zipline.data.bcolz_daily_bars.BcolzDailyBarReader"]
docstr: Internal implementation of write.
  
  `iterator` should be an iterator yielding pairs of (asset, ctable).
docstr_tok: ["Internal","implementation","of","write",".","`","iterator","`","should","be","an","iterator","yielding","pairs","of","(","asset",",","ctable",")","."]
code: def _write_internal(self, iterator, assets):
      """
      Internal implementation of write.
  
      `iterator` should be an iterator yielding pairs of (asset, ctable).
      """
      total_rows = 0
      first_row = {}
      last_row = {}
      calendar_offset = {}
  
      # Maps column name -> output carray.
      columns = {
          k: carray(array([], dtype=uint32_dtype))
          for k in US_EQUITY_PRICING_BCOLZ_COLUMNS
      }
  
      earliest_date = None
      sessions = self._calendar.sessions_in_range(
          self._start_session, self._end_session
      )
  
      if assets is not None:
  
          @apply
          def iterator(iterator=iterator, assets=set(assets)):
              for asset_id, table in iterator:
                  if asset_id not in assets:
                      raise ValueError("unknown asset id %r" % asset_id)
                  yield asset_id, table
  
      for asset_id, table in iterator:
          nrows = len(table)
          for column_name in columns:
              if column_name == "id":
                  # We know what the content of this column is, so don't
                  # bother reading it.
                  columns["id"].append(
                      full((nrows,), asset_id, dtype="uint32"),
                  )
                  continue
  
              columns[column_name].append(table[column_name])
  
          if earliest_date is None:
              earliest_date = table["day"][0]
          else:
              earliest_date = min(earliest_date, table["day"][0])
  
          # Bcolz doesn't support ints as keys in `attrs`, so convert
          # assets to strings for use as attr keys.
          asset_key = str(asset_id)
  
          # Calculate the index into the array of the first and last row
          # for this asset. This allows us to efficiently load single
          # assets when querying the data back out of the table.
          first_row[asset_key] = total_rows
          last_row[asset_key] = total_rows + nrows - 1
          total_rows += nrows
  
          table_day_to_session = compose(
              self._calendar.minute_to_session_label,
              partial(Timestamp, unit="s", tz="UTC"),
          )
          asset_first_day = table_day_to_session(table["day"][0])
          asset_last_day = table_day_to_session(table["day"][-1])
  
          asset_sessions = sessions[
              sessions.slice_indexer(asset_first_day, asset_last_day)
          ]
          assert len(table) == len(asset_sessions), (
              "Got {} rows for daily bars table with first day={}, last "
              "day={}, expected {} rows.\n"
              "Missing sessions: {}\n"
              "Extra sessions: {}".format(
                  len(table),
                  asset_first_day.date(),
                  asset_last_day.date(),
                  len(asset_sessions),
                  asset_sessions.difference(
                      to_datetime(
                          np.array(table["day"]),
                          unit="s",
                          utc=True,
                      )
                  ).tolist(),
                  to_datetime(
                      np.array(table["day"]),
                      unit="s",
                      utc=True,
                  )
                  .difference(asset_sessions)
                  .tolist(),
              )
          )
  
          # Calculate the number of trading days between the first date
          # in the stored data and the first date of **this** asset. This
          # offset used for output alignment by the reader.
          calendar_offset[asset_key] = sessions.get_loc(asset_first_day)
  
      # This writes the table to disk.
      full_table = ctable(
          columns=[
              columns[colname]
              for colname in US_EQUITY_PRICING_BCOLZ_COLUMNS
          ],
          names=US_EQUITY_PRICING_BCOLZ_COLUMNS,
          rootdir=self._filename,
          mode="w",
      )
  
      full_table.attrs["first_trading_day"] = (
          earliest_date if earliest_date is not None else iNaT
      )
  
      full_table.attrs["first_row"] = first_row
      full_table.attrs["last_row"] = last_row
      full_table.attrs["calendar_offset"] = calendar_offset
      full_table.attrs["calendar_name"] = self._calendar.name
      full_table.attrs["start_session_ns"] = self._start_session.value
      full_table.attrs["end_session_ns"] = self._end_session.value
      full_table.flush()
      return full_table
  
imports: from functools import partial
  import warnings
  from bcolz import carray, ctable
  import logbook
  import numpy
  from numpy import array, full, iinfo, nan
  from pandas import DatetimeIndex, NaT, read_csv, to_datetime, Timestamp
  from six import iteritems, viewkeys
  from toolz import compose
  from trading_calendars import get_calendar
  from zipline.data.session_bars import CurrencyAwareSessionBarReader
  from zipline.data.bar_reader import NoDataAfterDate, NoDataBeforeDate, NoDataOnDate
  from zipline.utils.functional import apply
  from zipline.utils.input_validation import expect_element
  from zipline.utils.numpy_utils import iNaT, float64_dtype, uint32_dtype
  from zipline.utils.memoize import lazyval
  from zipline.utils.cli import maybe_show_progress
  from ._equities import _compute_row_slices, _read_bcolz_data
label_desc: Use image node_id 6 for calling the BcolzDailyBarWriter obj's underlying member method code with example usage: obj._write_internal(iterator, assets) and returns: full_table