def Test_adjust_hk(self):
     """
     Test Difference between Hong Kong China Adjustment using a Random Sample
     random sample: stata_wtf90_hk_china_adjust_sitc4_check_sample.csv
     """
     OPTIONS = {
         'A': {
             'dropAX': False,
             'sitcr2': False,
             'drop_nonsitcr2': False,
             'adjust_hk': (False, None),
             'intertemp_cntrycode': False,
             'drop_incp_cntrycode': False,
             'adjust_units': False,
             'source_institution': 'un',
         },
         'B': {
             'dropAX': False,
             'sitcr2': False,
             'drop_nonsitcr2': False,
             'adjust_hk': (True, self.hkchina_rawdata),
             'intertemp_cntrycode': False,
             'drop_incp_cntrycode': False,
             'adjust_units': False,
             'source_institution': 'un',
         },
     }
     #-SITC Level 4-#
     A = construct_sitcr2(self.rawdata,
                          data_type='trade',
                          level=4,
                          **OPTIONS['A'])
     B = construct_sitcr2(self.rawdata,
                          data_type='trade',
                          level=4,
                          **OPTIONS['B'])
     RAW = pd.read_csv(TEST_DATA_DIR +
                       "stata_wtf90_hk_china_adjust_sitc4_check_sample.csv")
     for idx, row in RAW.iterrows():
         A_VAL = A.loc[(A.year == row.year) & (A.iiso3c == row.iiso3c) &
                       (A.eiso3c == row.eiso3c) &
                       (A.sitc4 == str(row.sitc4))]
         if len(A_VAL) == 0:
             print "Data not contained in A"
             continue
         A_VAL = A_VAL.get_value(index=A_VAL.index[0], col='value')
         assert A_VAL == row.value
         B_VAL = B.loc[(B.year == row.year) & (B.iiso3c == row.iiso3c) &
                       (B.eiso3c == row.eiso3c) &
                       (B.sitc4 == str(row.sitc4))]
         if len(B_VAL) == 0:
             print "Data not contained in B"
             continue
         B_VAL = B_VAL.get_value(index=B_VAL.index[0], col='value')
         assert B_VAL == row.value_adj
 def Test_adjust_hk(self):
     """
     Test Difference between Hong Kong China Adjustment using a Random Sample
     random sample: stata_wtf90_hk_china_adjust_sitc4_check_sample.csv
     """
     OPTIONS = {
             'A' :   {   'dropAX' : False,                    
                         'sitcr2' : False,                     
                         'drop_nonsitcr2' : False,            
                         'adjust_hk' : (False, None),                 
                         'intertemp_cntrycode' : False,        
                         'drop_incp_cntrycode' : False,        
                         'adjust_units' : False,
                         'source_institution' : 'un',
                     },
             'B' :   {   'dropAX' : False,                     
                         'sitcr2' : False,                     
                         'drop_nonsitcr2' : False,             
                         'adjust_hk' : (True, self.hkchina_rawdata),                   
                         'intertemp_cntrycode' : False,        
                         'drop_incp_cntrycode' : False,        
                         'adjust_units' : False,
                         'source_institution' : 'un',
                     },
             }
     #-SITC Level 4-#
     A = construct_sitcr2(self.rawdata, data_type='trade', level=4, **OPTIONS['A'])
     B = construct_sitcr2(self.rawdata, data_type='trade', level=4, **OPTIONS['B'])
     RAW = pd.read_csv(TEST_DATA_DIR + "stata_wtf90_hk_china_adjust_sitc4_check_sample.csv")
     for idx,row in RAW.iterrows():
         A_VAL = A.loc[(A.year == row.year) & (A.iiso3c == row.iiso3c) & (A.eiso3c == row.eiso3c) & (A.sitc4 == str(row.sitc4))]
         if len(A_VAL) == 0:
             print "Data not contained in A"
             continue
         A_VAL = A_VAL.get_value(index=A_VAL.index[0], col='value')
         assert A_VAL == row.value
         B_VAL = B.loc[(B.year == row.year) & (B.iiso3c == row.iiso3c) & (B.eiso3c == row.eiso3c) & (B.sitc4 == str(row.sitc4))]
         if len(B_VAL) == 0:
             print "Data not contained in B"
             continue
         B_VAL = B_VAL.get_value(index=B_VAL.index[0], col='value')
         assert B_VAL == row.value_adj
 def TestLevel1(self, verbose=True):
     """
     Test Level 1 Data Constructors
     """
     for dataset in SITC_DATASET_OPTIONS:
         if verbose: print "Testing DATASET Definition: %s" % dataset
         for data_type in DATA_TYPE:
             if verbose: print "Testing DATA_TYPE: %s" % data_type
             #-IF Adjust Hong Kong Data then Add Data to the Tuple-#
             if SITC_DATASET_OPTIONS[dataset]['adjust_hk'] == True: 
                 SITC_DATASET_OPTIONS[dataset]['adjust_hk'] = (True, self.hkchina_rawdata)
             else:
                 SITC_DATASET_OPTIONS[dataset]['adjust_hk'] = (False, None)
             data1 = construct_sitcr2(self.rawdata, data_type=data_type, level=1, **SITC_DATASET_OPTIONS[dataset])   #-Default Options-#
             data2 = construct_sitcr2l1(self.rawdata, data_type=data_type, **SITC_DATASET_OPTIONS[dataset])
             assert_frame_equal(data1, data2)
 def TestLevel1(self, verbose=True):
     """
     Test Level 1 Data Constructors
     """
     for dataset in SITC_DATASET_OPTIONS:
         if verbose: print "Testing DATASET Definition: %s" % dataset
         for data_type in DATA_TYPE:
             if verbose: print "Testing DATA_TYPE: %s" % data_type
             #-IF Adjust Hong Kong Data then Add Data to the Tuple-#
             if SITC_DATASET_OPTIONS[dataset]['adjust_hk'] == True:
                 SITC_DATASET_OPTIONS[dataset]['adjust_hk'] = (
                     True, self.hkchina_rawdata)
             else:
                 SITC_DATASET_OPTIONS[dataset]['adjust_hk'] = (False, None)
             data1 = construct_sitcr2(
                 self.rawdata,
                 data_type=data_type,
                 level=1,
                 **SITC_DATASET_OPTIONS[dataset])  #-Default Options-#
             data2 = construct_sitcr2l1(self.rawdata,
                                        data_type=data_type,
                                        **SITC_DATASET_OPTIONS[dataset])
             assert_frame_equal(data1, data2)
Example #5
0
     DATA_OPTIONS[dataset]['adjust_hk'] = (
         True, rawdata_hk
     )  #Add Data for construct_sitcr2l3 function, then remove so not saved as an attribute
 else:
     DATA_OPTIONS[dataset]['adjust_hk'] = (False, None)
 #-Intertemporal Product Codes-#
 if DATA_OPTIONS[dataset]['intertemp_productcode']:
     DATA_OPTIONS[dataset]['intertemp_productcode'] = (True,
                                                       ICP[4])
 else:
     DATA_OPTIONS[dataset]['intertemp_productcode'] = (False,
                                                       None)
 #-Compute Data-#
 data = construct_sitcr2(rawdata.copy(deep=True),
                         data_type=data_type,
                         level=4,
                         values_only=True,
                         **DATA_OPTIONS[dataset])
 store.put(dataset, data, format='table')
 #-Remove Hong Kong Data-#
 if DATA_OPTIONS[dataset]['adjust_hk'][0] == True:
     DATA_OPTIONS[dataset]['adjust_hk'] = True
 else:
     DATA_OPTIONS[dataset]['adjust_hk'] = False
 if DATA_OPTIONS[dataset]['intertemp_productcode'][0] == True:
     DATA_OPTIONS[dataset]['intertemp_productcode'] = True
 else:
     DATA_OPTIONS[dataset]['intertemp_productcode'] = False
 store.get_storer(dataset).attrs.options = DATA_OPTIONS[dataset]
 store.get_storer(dataset).attrs.data_type = data_type
 store.get_storer(
 store = pd.HDFStore(target_dir+fn, complevel=9, complib='zlib')
 #-Compute Datasets-#
 for dataset in sorted(DATA_OPTIONS.keys()):
     print "\n[SITCR2L4] Computing Dataset %s for %s" % (dataset, data_type)
     #-IF Adjust Hong Kong Data then Add Data to the Tuple-#
     if DATA_OPTIONS[dataset]['adjust_hk'] == True: 
         DATA_OPTIONS[dataset]['adjust_hk'] = (True, rawdata_hk)                     #Add Data for construct_sitcr2l3 function, then remove so not saved as an attribute
     else:
         DATA_OPTIONS[dataset]['adjust_hk'] = (False, None)
     #-Intertemporal Product Codes-#
     if DATA_OPTIONS[dataset]['intertemp_productcode']:
         DATA_OPTIONS[dataset]['intertemp_productcode'] = (True, ICP[4])
     else:
         DATA_OPTIONS[dataset]['intertemp_productcode'] = (False, None)
     #-Compute Data-#
     data = construct_sitcr2(rawdata.copy(deep=True), data_type=data_type, level=4, values_only=True, **DATA_OPTIONS[dataset])
     store.put(dataset, data, format='table')
     #-Remove Hong Kong Data-#
     if DATA_OPTIONS[dataset]['adjust_hk'][0] == True:
         DATA_OPTIONS[dataset]['adjust_hk'] = True
     else:
         DATA_OPTIONS[dataset]['adjust_hk'] = False
     if DATA_OPTIONS[dataset]['intertemp_productcode'][0] == True:
         DATA_OPTIONS[dataset]['intertemp_productcode'] = True
     else:
         DATA_OPTIONS[dataset]['intertemp_productcode'] = False
     store.get_storer(dataset).attrs.options = DATA_OPTIONS[dataset]
     store.get_storer(dataset).attrs.data_type = data_type
     store.get_storer(dataset).attrs.description = DATA_DESCRIPTION[dataset]
 print store
 #-Close-#