Пример #1
0
    def test_incorrect_dataset_id(self):
        """The method is testing if dataset id set up incorrectly"""

        with self.assertRaises(ValueError) as context:
            knoema.get('incorrect_id', somedim='val1;val2')

        self.assertTrue("Requested dataset doesn't exist or you don't have access to it." in str(context.exception))
Пример #2
0
    def test_empty_dimension_selection(self):
        """The method is testing if there are no elements in dimension selection"""

        with self.assertRaises(ValueError) as context:
            knoema.get('IMFWEO2017Apr', country='', subject='LP;NGDP')

        self.assertTrue('Selection for dimension Country is empty' in str(context.exception))
Пример #3
0
    def test_wrong_dimension_selection(self):
        """The method is testing if there are incorrect in dimension selection"""

        with self.assertRaises(ValueError) as context:
            knoema.get('IMFWEO2017Apr', country='914;512;111', subject='L1P;N1GDP')

        self.assertTrue('Selection for dimension Subject is empty' in str(context.exception))
Пример #4
0
    def test_none_dataset(self):
        """The method is testing if dataset set up as None"""

        with self.assertRaises(ValueError) as context:
            knoema.get(None)

        self.assertTrue('Dataset id is not specified' in str(context.exception))       
Пример #5
0
    def test_wrong_dimension(self):
        """The method is testing if there is wrong dimension name is specified"""
   
        with self.assertRaises(ValueError) as context:
            knoema.get('IMFWEO2017Apr', indicator='LP;NGDP')

        self.assertTrue('Dimension with id or name indicator is not found' in str(context.exception))
Пример #6
0
    def test_wrong_dimension_selection_transform(self):
        """The method is testing if there are incorrect in dimension selection"""

        with self.assertRaises(ValueError) as context:
            knoema.get('IMFWEO2017Apr', country='914;512;111', subject='LP;N1GDP', frequency='A')

        self.assertTrue('Selection for dimension Subject contains invalid elements' in str(context.exception))
    def test_no_selection(self):
        """The method is testing if there is no dimensions specified"""

        with self.assertRaises(ValueError) as context:
            knoema.get('IMFWEO2017Apr')

        self.assertTrue(
            'Dimensions members are not specified' in str(context.exception))
Пример #8
0
    def test_get_data_from_dataset_with_multiword_dimnames_and_metadata_and_mnemomics(self):
        """The method is testing load data from regular dataset with dimenions that have multi word names include metadata and mnemonics"""

        data_frame, metadata = knoema.get('xwfebbf', True,**{'Country': '1000000',
                                                    'Indicator': '1000000',
                                                    'Adjustment Type': '1000000',
                                                    'Conversion Type': '1000000'})

        self.assertEqual(data_frame.shape[0], 1)
        self.assertEqual(data_frame.shape[1], 1)
        self.assertEqual(metadata.shape[0], 7)
        self.assertEqual(metadata.shape[1], 1)
        self.assertEqual(['Country', 'Indicator', 'Adjustment Type','Conversion Type', 'Frequency'], data_frame.columns.names)
        self.assertEqual(['Country', 'Indicator', 'Adjustment Type','Conversion Type', 'Frequency'], metadata.columns.names)

        sname = ('China','GDP DEFLATOR (% CHANGE, AV)','Not seasonally adjusted', 'Average','A')

        indx = data_frame.first_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertAlmostEqual(value, 2.0)

        indx = metadata.first_valid_index()
        value = metadata.get_value(indx, sname)
        self.assertAlmostEqual(value, 'CN')

        self.assertAlmostEqual(metadata.get_value('Unit', sname), 'Unit')
        self.assertAlmostEqual(metadata.get_value('Scale', sname), 1.0)
        self.assertAlmostEqual(metadata.get_value('Mnemonics', sname), 'RRRRRRRRR')
    def test_getdata_singleseries_difffrequencies_by_member_id(self):
        """The method is testing getting single series on different frequencies by dimension member ids"""

        data_frame = knoema.get('MEI_BTS_COS_2015',
                                location='AT',
                                subject='BSCI',
                                measure='blsa')
        self.assertEqual(data_frame.shape[0], 390)
        self.assertEqual(data_frame.shape[1], 2)

        indx = data_frame.first_valid_index()
        sname = 'Austria - Confidence indicators - Balance, s.a. - M'
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, -5.0)

        indx = data_frame.last_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 2.0)

        indx = data_frame.first_valid_index()
        sname = 'Austria - Confidence indicators - Balance, s.a. - Q'
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, -5.233333)

        value = data_frame.get_value(datetime.datetime(2017, 1, 1), sname)
        self.assertEqual(value, 1.566667)
    def test_get_data_from_dataset_by_dim_ids(self):
        """The method is testing load data from regular dataset with dimenions that have multi word names by dim ids"""

        data_frame = knoema.get(
            'FDI_FLOW_CTRY', **{
                'Reporting-country': 'AUS',
                'Partner-country': 'w0',
                'Measurement-principle': 'DI',
                'Type-of-FDI': 'T_FA_F',
                'Type-of-entity': 'ALL',
                'Accounting-entry': 'NET',
                'Level-of-counterpart': 'IMC',
                'Currency': 'USD'
            })

        self.assertEqual(data_frame.shape[0], 7)
        self.assertEqual(data_frame.shape[1], 1)

        sname = 'Australia - WORLD - Directional principle: Inward - FDI financial flows - Total - All resident units - Net - Immediate counterpart (Immediate investor or immediate host) - US Dollar - A'

        indx = data_frame.first_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertAlmostEqual(value, 31666.667, 3)

        indx = data_frame.last_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertAlmostEqual(value, 22267.638, 3)
    def test_not_all_dims_in_filter(self):
        """The method is testing if dataset id set up incorrectly"""

        with self.assertRaises(ValueError) as context:
            knoema.get(
                'bmlaaaf', **{
                    'Country': 'Albania',
                    'Borrower': 'Ministry of Finance',
                    'Guarantor': 'Albania',
                    'Loan type': 'B loan',
                    'Loan status': 'EFFECTIVE'
                })

        self.assertTrue(
            'The following dimension(s) are not set: Currency of Commitment, Measure'
            in str(context.exception))
Пример #12
0
    def test_get_data_from_dataset_with_multiword_dimnames_and_metadata_transform(self):
        """The method is testing load data from regular dataset with dimenions that have multi word names include metadata"""
  
        data_frame, metadata = knoema.get('FDI_FLOW_CTRY', True,**{'Reporting country': 'AUS',
                                                    'Partner country/territory': 'w0',
                                                    'Measurement principle': 'DI',
                                                    'Type of FDI': 'T_FA_F',
                                                    'Type of entity': 'ALL',
                                                    'Accounting entry': 'NET',
                                                    'Level of counterpart': 'IMC',
                                                    'Currency': 'USD',
                                                    'Frequency': 'A'})

        self.assertEqual(data_frame.shape[0], 7)
        self.assertEqual(data_frame.shape[1], 1)

        sname = ('Australia','WORLD','Directional principle: Inward','FDI financial flows - Total','All resident units','Net','Immediate counterpart (Immediate investor or immediate host)','US Dollar','A')

        indx = data_frame.first_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertAlmostEqual(value, 31666.667, 3)

        indx = data_frame.last_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertAlmostEqual(value, 22267.638, 3)
Пример #13
0
 def test_search_by_mnemonics_data_by_all_datasets(self):
     """The method is testing searching by mnemonics by all dataset and returns data"""
     data_frame = knoema.get(mnemonics='512NGDP_A_in_test_dataset;512NGDP')
     self.assertEqual(data_frame.shape[1], 2)
     sname = ('512NGDP_A_in_test_dataset')
     indx = data_frame.first_valid_index()
     value = data_frame.get_value(indx, sname)
     self.assertEqual(value, 0)
Пример #14
0
    def test_incorrect_host_knoema_get(self):
        """The method is negative test on get series from dataset with incorrect host"""

        with self.assertRaises(ValueError) as context:
            apicfg = knoema.ApiConfig()
            apicfg.host = 'knoema_incorect.com'
            data_frame = knoema.get('IMFWEO2017Apr', country='914', subject='ngdp')
        self.assertTrue("The specified host knoema_incorect.com does not exist" in str(context.exception))
Пример #15
0
    def test_getdata_multiseries_multifrequency_by_member_id_range(self):
        """The method is testing getting mulitple series queriing mulitple frequencies by dimension member ids with time range"""

        data_frame = knoema.get('MEI_BTS_COS_2015', location='AT;BE', subject='BSCI', measure='blsa', frequency='Q;M', timerange='2010M1-2015M12')
        self.assertEqual(data_frame.shape[1], 3)

        sname = ('Austria', 'Confidence indicators', 'Balance; Seasonally adjusted', 'M')
        value = data_frame.get_value(datetime.datetime(2012, 12, 1), sname)
        self.assertEqual(value, -12.4)
Пример #16
0
    def test_search_by_mnemonics_data(self):
        """The method is testing searching by mnemonics"""

        data_frame = knoema.get('eqohmpb', mnemonics='512NGDP_A_in_test_dataset')
        self.assertEqual(data_frame.shape[1], 1)
        sname = ('512NGDP_A_in_test_dataset')
        indx = data_frame.first_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 0)
Пример #17
0
  def test_weekly_frequency(self):
      """The method is testing load data from regular dataset by weekly frequency"""
 
      data = knoema.get('WOERDP2015', location='China', Indicator='EMBI Sovereign Spreads (Basis points)', frequency='W')
      sname = ('China', 'EMBI Sovereign Spreads (Basis points)', 'W')
      value = data.get_value(datetime.datetime(2010, 1, 4), sname)
      self.assertEqual(value, 44)
      value = data.get_value(datetime.datetime(2015, 9, 7), sname)
      self.assertEqual(value, 183)
Пример #18
0
    def test_getdata_multiseries_singlefrequency_by_member_id(self):
        """The method is testing getting mulitple series with one frequency by dimension member ids"""

        data_frame = knoema.get('MEI_BTS_COS_2015', location=['AT', 'AU'], subject='BSCI', measure='blsa', frequency='Q')
        self.assertEqual(data_frame.shape[1], 2)

        sname = ('Austria', 'Confidence indicators', 'Balance; Seasonally adjusted', 'Q')
        value = data_frame.get_value(datetime.datetime(2017, 1, 1), sname)
        self.assertEqual(value, 1.566667)
Пример #19
0
    def test_get_data_from_flat_dataset_with_datecolumn(self):
        """The method is testing load data from flat dataset with specifying datecolumn"""

        data_frame = knoema.get('bjxchy', country='Albania', measure='Original Principal Amount ($)', datecolumn='Effective Date (Most Recent)', timerange='2010-2015', frequency='A')
        self.assertEqual(data_frame.shape[0], 5)
        self.assertEqual(data_frame.shape[1], 5)

        sname = ('Albania', 'MINISTRY OF FINANCE', 'Albania', 'FSL', 'Disbursing', 'Original Principal Amount ($)', 'A')
        value = data_frame.get_value('2013-01-01', sname)
        self.assertEqual(value, 40000000.0)
Пример #20
0
    def test_get_data_from_flat_dataset(self):
        """The method is testing load data from flat dataset"""

        data_frame = knoema.get('cblymmf', Country='Albania;Australia', Keyword='FGP;TWP;TRP')
        self.assertEqual(data_frame.shape[0], 1)
        self.assertEqual(data_frame.shape[1], 4)

        sname = ('Albania', 'FGP', 'D')
        value = data_frame.get_value('All time', sname)
        self.assertEqual(value, 8.0)
Пример #21
0
    def test_get_data_with_partial_selection_with_metadata(self):
        """The method is testing getting series with partial selection"""

        data_frame, metadata = knoema.get('IMFWEO2017Apr', True, subject = 'flibor6')
        self.assertEqual(metadata.shape[1], 2)
        self.assertEqual(['Country', 'Subject', 'Frequency'], metadata.columns.names)
        sname = ('Japan', 'Six-month London interbank offered rate (LIBOR) (Percent)', 'A')
        self.assertEqual(metadata.get_value('Country Id',sname),'158')
        self.assertEqual(metadata.get_value('Subject Id',sname),'FLIBOR6')
        self.assertEqual(metadata.get_value('Unit',sname),'Percent')
Пример #22
0
    def test_get_all_series_from_dataset(self):
        """The method is testing getting all series from dataset"""
        data_frame= knoema.get('eqohmpb')
        self.assertEqual(data_frame.shape[1], 14)
        self.assertEqual(['Country', 'Indicator', 'Frequency'], data_frame.columns.names)

        indx = data_frame.first_valid_index()
        sname = ('Afghanistan', 'Gross domestic product, current prices', 'M')
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 26.02858277)
Пример #23
0
def get_stock_us(sym, start, end):

    frame = knoema.get(
        'USINDSSP2017', **{
            'timerange': start + '-' + end,
            'frequency': 'D',
            'Company': sym,
            'indicator': 'KN.A1;KN.A2;KN.A3;KN.A4;KN.A5'
        })

    return frame
Пример #24
0
 def test_search_by_mnemonics_with_metadata_by_all_datasets(self):
     """The method is testing searching by mnemonics by all dataset and returns data and metadata"""
     data_frame, metadata = knoema.get(None, True, mnemonics='512NGDP_A_in_test_dataset;512NGDP')
     self.assertEqual(data_frame.shape[1], 2)
     sname = ('512NGDP_A_in_test_dataset')
     indx = data_frame.first_valid_index()
     value = data_frame.get_value(indx, sname)
     self.assertEqual(value, 0)
     self.assertEqual(metadata.get_value('Country Id',sname),'512')
     self.assertEqual(metadata.get_value('Indicator Id',sname),'NGDP')
     self.assertEqual(metadata.get_value('Unit',sname),'Number')       
     self.assertEqual(metadata.get_value('Mnemonics',sname),'512NGDP_A_in_test_dataset')  
Пример #25
0
    def test_get_data_from_flat_dataset_without_time(self):
        """The method is testing load data from flat dataset without time"""

        data_frame = knoema.get('pocqwkd', **{'Object type': 'Airports',
                                              'Object name': 'Bakel airport'})

        self.assertEqual(data_frame.shape[0], 1)
        self.assertEqual(data_frame.shape[1], 1)

        sname = ('Airports', 'Bakel Airport', '')
        value = data_frame.get_value('All time', sname)
        self.assertEqual(value, 1.0)
    def test_getdata_multiseries_multifrequency_by_member_id(self):
        """The method is testing getting mulitple series queriing mulitple frequencies by dimension member ids"""

        data_frame = knoema.get('MEI_BTS_COS_2015',
                                location='AT;AU',
                                subject='BSCI',
                                measure='blsa',
                                frequency='Q;M')
        self.assertEqual(data_frame.shape[0], 465)
        self.assertEqual(data_frame.shape[1], 3)

        sname = 'Austria - Confidence indicators - Balance, s.a. - M'
        value = data_frame.get_value(datetime.datetime(2017, 3, 1), sname)
        self.assertEqual(value, 2.4)
Пример #27
0
    def test_getdata_multiseries_by_member_id_range(self):
        """The method is testing getting multiple series by dimension member ids and time range"""
        data_frame = knoema.get('IMFWEO2017Apr', country='914;512;111', subject='lp;ngdp', timerange='2015-2020')

        self.assertEqual(data_frame.shape[0], 6)
        self.assertEqual(data_frame.shape[1], 6)

        indx = data_frame.first_valid_index()
        sname = ('United States', 'Gross domestic product, current prices (National currency)', 'A')
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 18036.650)

        indx = data_frame.last_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 22063.044)
Пример #28
0
    def test_search_by_mnemonics_with_metadata(self):
        """The method is testing searching by mnemonics with metadata"""

        data_frame, metadata = knoema.get('eqohmpb', True, mnemonics='512NGDP_A_in_test_dataset')
        self.assertEqual(data_frame.shape[1], 1)
        sname = ('512NGDP_A_in_test_dataset')
        indx = data_frame.first_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 0)
        self.assertEqual(metadata.shape[1], 1)
        self.assertEqual(metadata.shape[0], 5)
        self.assertEqual(metadata.get_value('Country Id',sname),'512')
        self.assertEqual(metadata.get_value('Indicator Id',sname),'NGDP')
        self.assertEqual(metadata.get_value('Unit',sname),'Number')       
        self.assertEqual(metadata.get_value('Mnemonics',sname),'512NGDP_A_in_test_dataset')  
Пример #29
0
    def test_get_data_with_partial_selection(self):
        """The method is testing getting series with partial selection"""

        data_frame = knoema.get('IMFWEO2017Apr', subject = 'flibor6')
        self.assertEqual(data_frame.shape[1], 2)
        self.assertEqual(['Country', 'Subject', 'Frequency'], data_frame.columns.names)

        indx = data_frame.first_valid_index()
        sname = ('Japan', 'Six-month London interbank offered rate (LIBOR) (Percent)', 'A')
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 10.861)

        indx = data_frame.index[38]
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 0.048)
Пример #30
0
    def test_getdata_multiseries_by_member_key(self):
        """The method is testing getting multiple series by dimension member keys"""

        data_frame = knoema.get('IMFWEO2017Apr', country='1000010;1000000;1001830', subject='1000370;1000040')
        self.assertEqual(data_frame.shape[0], 43)
        self.assertEqual(data_frame.shape[1], 6)

        indx = data_frame.first_valid_index()
        sname = ('United States', 'Gross domestic product, current prices (National currency)', 'A')
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 2862.475)

        indx = data_frame.last_valid_index()
        value = data_frame.get_value(indx, sname)
        self.assertEqual(value, 23760.331)