Write the OHLCV data for one country to the HDF5 file.

        Parameters
        ----------
        country_code : str
            The ISO 3166 alpha-2 country code for this country.
        frames : dict[str, pd.DataFrame]
            A dict mapping each OHLCV field to a dataframe with a row
            for each date and a column for each sid. The dataframes need
            to have the same index and columns.
        scaling_factors : dict[str, float], optional
            A dict mapping each OHLCV field to a scaling factor, which
            is applied (as a multiplier) to the values of field to
            efficiently store them as uint32, while maintaining desired
            precision. These factors are written to the file as metadata,
            which is consumed by the reader to adjust back to the original
            float values. Default is None, in which case
            DEFAULT_SCALING_FACTORS is used.

def write(self, country_code, frames, scaling_factors=None):
        """Write the OHLCV data for one country to the HDF5 file.

        Parameters
        ----------
        country_code : str
            The ISO 3166 alpha-2 country code for this country.
        frames : dict[str, pd.DataFrame]
            A dict mapping each OHLCV field to a dataframe with a row
            for each date and a column for each sid. The dataframes need
            to have the same index and columns.
        scaling_factors : dict[str, float], optional
            A dict mapping each OHLCV field to a scaling factor, which
            is applied (as a multiplier) to the values of field to
            efficiently store them as uint32, while maintaining desired
            precision. These factors are written to the file as metadata,
            which is consumed by the reader to adjust back to the original
            float values. Default is None, in which case
            DEFAULT_SCALING_FACTORS is used.
        """
        if scaling_factors is None:
            scaling_factors = DEFAULT_SCALING_FACTORS

        with self.h5_file(mode='a') as h5_file:
            # ensure that the file version has been written
            h5_file.attrs['version'] = VERSION

            country_group = h5_file.create_group(country_code)

            data_group = country_group.create_group(DATA)
            index_group = country_group.create_group(INDEX)
            lifetimes_group = country_group.create_group(LIFETIMES)

            # Note that this functions validates that all of the frames
            # share the same days and sids.
            days, sids = days_and_sids_for_frames(list(frames.values()))

            # Write sid and date indices.
            index_group.create_dataset(SID, data=sids)

            # h5py does not support datetimes, so they need to be stored
            # as integers.
            index_group.create_dataset(DAY, data=days.astype(np.int64))

            log.debug(
                'Wrote {} group to file {}',
                index_group.name,
                self._filename,
            )

            # Write start and end dates for each sid.
            start_date_ixs, end_date_ixs = compute_asset_lifetimes(frames)

            lifetimes_group.create_dataset(START_DATE, data=start_date_ixs)
            lifetimes_group.create_dataset(END_DATE, data=end_date_ixs)

            if len(sids):
                chunks = (len(sids), min(self._date_chunk_size, len(days)))
            else:
                # h5py crashes if we provide chunks for empty data.
                chunks = None

            for field in FIELDS:
                frame = frames[field]

                # Sort rows by increasing sid, and columns by increasing date.
                frame.sort_index(inplace=True)
                frame.sort_index(axis='columns', inplace=True)

                data = coerce_to_uint32(
                    frame.T.fillna(0).values,
                    scaling_factors[field],
                )

                dataset = data_group.create_dataset(
                    field,
                    compression='lzf',
                    shuffle=True,
                    data=data,
                    chunks=chunks,
                )

                dataset.attrs[SCALING_FACTOR] = scaling_factors[field]

                log.debug(
                    'Writing dataset {} to file {}',
                    dataset.name, self._filename
                )