예제 #1
0
    def __init__(self, verbose=True):
        """
        Initialise Class and Populate with Data From Package

        ..  Future Work
            -----------
            [1] Allow specification of User File
        """
        # - Attributes - #
        self._fn = u"unstats_CountryCodeAndNameToISO2ISO3.xls"
        if sys.platform.startswith('win'):
            self._md5hash = "57f8ffd8638e77354c312823f13cb867"  #Why does this keep changing?
        else:
            self._md5hash = "0ae80063248db7a9446d155c1360345d"  #This is the md5sum on the mac?
        self._fl = _util.package_folder(__file__, "data") + self._fn

        # --> This Requires Debugging <-- #
        #
        # if _util.verify_md5hash(self._fl, self._md5hash):
        #   self.data   = _pd.read_excel(self._fl, )
        # else:
        #   raise ValueError("Object's md5hash (%s) doesn't match the md5hash of the package data file!" % self._md5hash)
        #
        # ---> END Debugging < -- #
        # - Acquire Data From Package - #
        self.data = _pd.read_excel(self._fl)
        if verbose:
            print '[INFO] Loaded UN Country Codes from file %s \nLocation: %s\n' % (
                self._fn, self._fl)

        # - Drop Data - #
        for item in self.drop:
            if verbose: print "Dropping: %s" % (item)
            del self.data[item]
        if verbose: print ""

        # - Recode Data - #
        self.data = _util.recode_index(self.data,
                                       self.recodes,
                                       axis='columns',
                                       verbose=verbose)
예제 #2
0
파일: iso3166.py 프로젝트: amrscs/ps
    def __init__(self, iso3n_numeric=True, verbose=True):
        """
        Initialise Class and Populate with Data From Package

        Parameters
        ----------
        iso3n_numeric     :     Bool, optional(default=True)
                                Ensure iso3n is converted to integer numeric data

        ..  Future Work
            -----------
            [1] Add md5 checksum check
            [2] Remove numeric as it isn't acting as an "option"

        """
        # - Attributes - #
        self.__fn       = u"linuxmint16_iso_3166.xml"
        self.__fl       = _util.package_folder(__file__, "data") + self.__fn

        # - Acquire Data From Package - #
        if verbose: print '[INFO] Loaded Country Codes from iso_3166 xml file %s \nLocation: %s\n' % (self.__fn, self.__fl)
        xml  = xmltodict.parse(open(self.__fl))
        data = _pd.DataFrame()
        for item in xml['iso_3166_entries']['iso_3166_entry']:
            iso2c = item['@alpha_2_code']
            iso3c = item['@alpha_3_code']
            iso3n = item['@numeric_code']
            name  = item['@name']
            try:
                official_name = item['@official_name']
            except: 
                official_name = ''
            row = {'iso2c' : iso2c, 'iso3c' : iso3c, 'iso3n' : iso3n, 'countryname' : name, 'official_name' : official_name}
            data = data.append(row, ignore_index=True)

        #-Parse Option: numeric-#
        if iso3n_numeric == True:
            data['iso3n'] = data['iso3n'].apply(lambda x: int(x))

        # - Recode Data - #
        self.data = data
예제 #3
0
    def __init__(self, verbose=True):
        """
        Initialise Class and Populate with Data From Package

        ..  Future Work
            -----------
            [1] Allow specification of User File
        """
        # - Attributes - #
        self._fn        = u"unstats_CountryCodeAndNameToISO2ISO3.xls"
        if sys.platform.startswith('win'):
            self._md5hash   = "57f8ffd8638e77354c312823f13cb867"                        #Why does this keep changing?
        else:
            self._md5hash   = "0ae80063248db7a9446d155c1360345d"                        #This is the md5sum on the mac?
        self._fl        = _util.package_folder(__file__, "data") + self._fn

            # --> This Requires Debugging <-- #
            #
            # if _util.verify_md5hash(self._fl, self._md5hash):
            #   self.data   = _pd.read_excel(self._fl, )
            # else:
            #   raise ValueError("Object's md5hash (%s) doesn't match the md5hash of the package data file!" % self._md5hash)
            #
            # ---> END Debugging < -- #
        # - Acquire Data From Package - #
        self.data   = _pd.read_excel(self._fl)
        if verbose: print '[INFO] Loaded UN Country Codes from file %s \nLocation: %s\n' % (self._fn, self._fl)

        # - Drop Data - #
        for item in self.drop:
            if verbose: print "Dropping: %s" % (item)
            del self.data[item]
        if verbose: print ""

        # - Recode Data - #
        self.data = _util.recode_index(self.data, self.recodes, axis='columns', verbose=verbose)
"""
Tests for DynamicProductLevelExportSystem Module
"""

import pandas as pd
from pyeconlab.util import package_folder
from pyeconlab.trade.systems import DynamicProductLevelExportSystem

from pandas.util.testing import assert_frame_equal

### --- Options --- ###
verbose = False

#-DATA Paths-#
TEST_DATA_DIR = package_folder(__file__, "data") 

class TestDynamicProductLevelExportSystemBasic(object):
	"""
	Basic Tests for Dynamic Product Level Export System
	"""

	odata = pd.DataFrame([	[2000,"AUS","0001",200], 
							[2000,"AUS","0002",100],
							[2000,"USA","0001",400],
							[2000,"USA","0003",300],
							[2000,"AFG","0004",50],
							[2001,"AFG","0004",25],
							[2001,"AUS","0005",30],
							[2001,"AUS","0001",100],
							[2001,"USA","0004",200],
							[2001,"USA","0006",500],
예제 #5
0
"""
Tests for DynamicProductLevelExportSystem Module
"""

import pandas as pd
from pyeconlab.util import package_folder
from pyeconlab.trade.systems import DynamicProductLevelExportSystem

from pandas.util.testing import assert_frame_equal

### --- Options --- ###
verbose = False

#-DATA Paths-#
TEST_DATA_DIR = package_folder(__file__, "data")


class TestDynamicProductLevelExportSystemBasic(object):
    """
	Basic Tests for Dynamic Product Level Export System
	"""

    odata = pd.DataFrame(
        [[2000, "AUS", "0001", 200], [2000, "AUS", "0002", 100],
         [2000, "USA", "0001", 400], [2000, "USA", "0003", 300],
         [2000, "AFG", "0004", 50], [2001, "AFG", "0004", 25],
         [2001, "AUS", "0005", 30], [2001, "AUS", "0001", 100],
         [2001, "USA", "0004", 200], [2001, "USA", "0006", 500],
         [2001, "USA", "0007", 900]],
        columns=['year', 'country', 'productcode', 'export'])