def data(self, **options):
     # handle_not_found_error if set to True will add an empty DataFrame
     # for a non-existent dataset instead of raising an error
     handle_not_found_error = options.pop('handle_not_found_error', False)
     handle_column_not_found = options.pop('handle_column_not_found', False)
     # default order to ascending, and respect whatever user passes in
     params = {
         'database_code': self.database_code,
         'dataset_code': self.dataset_code,
         'order': 'asc'
     }
     updated_options = Util.merge_options('params', params, **options)
     try:
         return Data.all(**updated_options)
     except NotFoundError:
         if handle_not_found_error:
             return DataList(
                 Data, [],
                 {'column_names': [six.u('None'),
                                   six.u('Not Found')]})
         raise
     except ColumnNotFound:
         if handle_column_not_found:
             return DataList(
                 Data, [],
                 {'column_names': [six.u('None'),
                                   six.u('Not Found')]})
         raise
Exemple #2
0
 def test_merge_options_when_key_doesnt_exist_in_options(self):
     params = {'foo': 'bar', 'foo2': 'bar2'}
     options = {'params': {'foo3': 'bar3'}}
     merged = Util.merge_options('params', params, **options)
     self.assertDictEqual(
         merged, {'params': {'foo': 'bar',
                             'foo2': 'bar2', 'foo3': 'bar3'}})
Exemple #3
0
 def test_merge_options_when_key_doesnt_exist_in_options(self):
     params = {'foo': 'bar', 'foo2': 'bar2'}
     options = {'params': {'foo3': 'bar3'}}
     merged = Util.merge_options('params', params, **options)
     self.assertDictEqual(
         merged, {'params': {'foo': 'bar',
                             'foo2': 'bar2', 'foo3': 'bar3'}})
 def _get_dataset_data(self, dataset, **options):
     updated_options = options
     # if we have only one column index, let the api
     # handle the column filtering since the api supports this
     if len(dataset.requested_column_indexes) == 1:
         params = {'column_index': dataset.requested_column_indexes[0]}
         # only change the options per request
         updated_options = options.copy()
         updated_options = Util.merge_options('params', params, **updated_options)
     return dataset.data(**updated_options)
Exemple #5
0
 def _get_dataset_data(self, dataset, **options):
     updated_options = options
     # if we have only one column index, let the api
     # handle the column filtering since the api supports this
     if len(dataset.requested_column_indexes) == 1:
         params = {'column_index': dataset.requested_column_indexes[0]}
         # only change the options per request
         updated_options = options.copy()
         updated_options = Util.merge_options('params', params,
                                              **updated_options)
     return dataset.data(**updated_options)
Exemple #6
0
    def __get_raw_data__(self):
        if self._raw_data:
            return self._raw_data

        cls = self.__class__
        params = {'id': str(self.code)}
        options = Util.merge_options('params', params, **self.options)

        path = Util.constructed_path(cls.get_path(), options['params'])

        r = Connection.request('get', path, **options)
        response_data = r.json()
        Util.convert_to_dates(response_data)
        self._raw_data = response_data[singularize(cls.lookup_key())]
        return self._raw_data
Exemple #7
0
 def data(self, **options):
     # handle_not_found_error if set to True will add an empty DataFrame
     # for a non-existent dataset instead of raising an error
     handle_not_found_error = options.pop('handle_not_found_error', False)
     handle_column_not_found = options.pop('handle_column_not_found', False)
     # default order to ascending, and respect whatever user passes in
     params = {
         'database_code': self.database_code,
         'dataset_code': self.dataset_code,
         'order': 'asc'
     }
     updated_options = Util.merge_options('params', params, **options)
     try:
         return Data.all(**updated_options)
     except NotFoundError:
         if handle_not_found_error:
             return DataList(Data, [], {'column_names': [six.u('None'), six.u('Not Found')]})
         raise
     except ColumnNotFound:
         if handle_column_not_found:
             return DataList(Data, [], {'column_names': [six.u('None'), six.u('Not Found')]})
         raise
 def datasets(self, **options):
     params = {'database_code': self.code, 'query': '', 'page': 1}
     options = Util.merge_options('params', params, **options)
     return quandl.model.dataset.Dataset.all(**options)
 def datasets(self, **options):
     params = {'database_code': self.code, 'query': '', 'page': 1}
     options = Util.merge_options('params', params, **options)
     return quandl.model.dataset.Dataset.all(**options)