Repository: quantopian/zipline
File: zipline/data/hdf5_daily_bars.py (Python)

Code before:

        Parameters
        ----------
        path : str
            Path to an HDF5 daily pricing file.
        """
        return cls.from_file(h5py.File(path))

    @property
    def countries(self):
        """A set-like object of the country codes supplied by this reader.
        """
        return viewkeys(self._readers)

    def _country_code_for_assets(self, assets):
        unique_country_codes = self._country_map.get(assets).dropna().unique()

        if len(unique_country_codes) > 1:
            raise NotImplementedError(
                (
                    'Assets were requested from multiple countries ({}),'
                    ' but multi-country reads are not yet supported.'
                ).format(list(unique_country_codes))
            )
        elif len(unique_country_codes) == 0:
            return self._country_map.iloc[0]

        return np.asscalar(unique_country_codes)

    def load_raw_arrays(self,
                        columns,
                        start_date,
                        end_date,
                        assets):
        """
        Parameters
        ----------
        columns : list of str
           'open', 'high', 'low', 'close', or 'volume'
        start_date: Timestamp
           Beginning of the window range.
        end_date: Timestamp
           End of the window range.
        assets : list of int
           The asset identifiers in the window.

        Returns
        -------
        list of np.ndarray
            A list with an entry per field of ndarrays with shape
            (minutes in range, sids) with a dtype of float64, containing the

Review comment (suggestion):
I would probably raise a special exception or return a sentinel value for this case (I think this is the "all assets are unknown" case?), for two reasons:

1. If another consumer comes along and uses this method, it seems likely that this could cause unexpected behavior without being noticed.
2. We can special case this to just return an array full of missing values without needing to dispatch to a per-country reader, which would be a perf win (albeit a win on a pretty marginal case...).

Code after:
        """
        return cls({
            country: HDF5DailyBarReader.from_file(h5_file, country)
            for country in h5_file.keys()
        })

    @classmethod
    def from_path(cls, path):
        """
        Construct from a file path.

        Parameters
        ----------
        path : str
            Path to an HDF5 daily pricing file.
        """
        return cls.from_file(h5py.File(path))

    @property
    def countries(self):
        """A set-like object of the country codes supplied by this reader.
        """
        return viewkeys(self._readers)

    def _country_code_for_assets(self, assets):
        country_codes = self._country_map.get(assets)

        # In some versions of pandas (observed in 0.22), Series.get()
        # returns None if none of the labels are in the index.
        if country_codes is not None:
            unique_country_codes = country_codes.dropna().unique()
            num_countries = len(unique_country_codes)
        else:
            num_countries = 0

        if num_countries == 0:
            raise ValueError('At least one valid asset id is required.')
        elif num_countries > 1:
            raise NotImplementedError(
                (
                    'Assets were requested from multiple countries ({}),'
                    ' but multi-country reads are not yet supported.'
                ).format(list(unique_country_codes))
            )

        return np.asscalar(unique_country_codes)

    def load_raw_arrays(self,
                        columns,
                        start_date,
                        end_date,