Example #1
0
    def test_wdi_download_str(self):

        # These are the expected results, rounded (robust against
        # data revisions in the future).
        expected = {
            "NY.GDP.PCAP.CD": {
                ("Japan", "2004"): 38000.0,
                ("Japan", "2003"): 35000.0,
                ("Japan", "2002"): 32000.0,
                ("Japan", "2001"): 34000.0,
                ("Japan", "2000"): 39000.0,
            }
        }
        expected = pd.DataFrame(expected)
        expected = expected.sort_index()

        cntry_codes = "JP"
        inds = "NY.GDP.PCAP.CD"
        result = download(
            country=cntry_codes, indicator=inds, start=2000, end=2004, errors="ignore"
        )
        result = result.sort_index()
        result = np.round(result, decimals=-3)

        expected.index.names = ["country", "year"]
        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(
            inds, countries=cntry_codes, start=2000, end=2004, errors="ignore"
        ).read()
        result = result.sort_index()
        result = np.round(result, decimals=-3)
        tm.assert_frame_equal(result, expected)
Example #2
0
    def test_wdi_download_str(self):

        expected = {
            'NY.GDP.PCAP.CD': {
                ('Japan', '2004'): 36441.50449394,
                ('Japan', '2003'): 33690.93772972,
                ('Japan', '2002'): 31235.58818439,
                ('Japan', '2001'): 32716.41867489,
                ('Japan', '2000'): 37299.64412913
            }
        }
        expected = pd.DataFrame(expected)
        # Round, to ignore revisions to data.
        expected = np.round(expected, decimals=-3)
        if PANDAS_0170:
            expected = expected.sort_index()
        else:
            expected = expected.sort()

        cntry_codes = 'JP'
        inds = 'NY.GDP.PCAP.CD'
        result = download(country=cntry_codes,
                          indicator=inds,
                          start=2000,
                          end=2004,
                          errors='ignore')
        if PANDAS_0170:
            result = result.sort_index()
        else:
            result = result.sort()
        result = np.round(result, decimals=-3)

        if PANDAS_0140:
            expected.index.names = ['country', 'year']
        else:
            # prior versions doesn't allow to set multiple names to MultiIndex
            # Thus overwrite it with the result
            expected.index = result.index

        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds,
                                 countries=cntry_codes,
                                 start=2000,
                                 end=2004,
                                 errors='ignore').read()
        if PANDAS_0170:
            result = result.sort_index()
        else:
            result = result.sort()
        result = np.round(result, decimals=-3)
        tm.assert_frame_equal(result, expected)
    def test_wdi_download_monthly(self):
        expected = {'COPPER': {('World', '2012M01'): 8040.47,
                               ('World', '2011M12'): 7565.48,
                               ('World', '2011M11'): 7581.02,
                               ('World', '2011M10'): 7394.19,
                               ('World', '2011M09'): 8300.14,
                               ('World', '2011M08'): 9000.76,
                               ('World', '2011M07'): 9650.46,
                               ('World', '2011M06'): 9066.85,
                               ('World', '2011M05'): 8959.90,
                               ('World', '2011M04'): 9492.79,
                               ('World', '2011M03'): 9503.36,
                               ('World', '2011M02'): 9867.60,
                               ('World', '2011M01'): 9555.70}}
        expected = pd.DataFrame(expected)
        # Round, to ignore revisions to data.
        expected = np.round(expected, decimals=-3)
        if PANDAS_0170:
            expected = expected.sort_index()
        else:
            expected = expected.sort()

        cntry_codes = 'ALL'
        inds = 'COPPER'
        result = download(country=cntry_codes, indicator=inds,
                          start=2011, end=2012, freq='M',errors='ignore')
        if PANDAS_0170:
            result = result.sort_index()
        else:
            result = result.sort()
        result = np.round(result, decimals=-3)

        if PANDAS_0140:
            expected.index.names = ['country', 'year']
        else:
            # prior versions doesn't allow to set multiple names to MultiIndex
            # Thus overwrite it with the result
            expected.index = result.index

        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds, countries=cntry_codes,
                                 start=2011, end=2012, freq='M', errors='ignore').read()
        if PANDAS_0170:
            result = result.sort_index()
        else:
            result = result.sort()
        result = np.round(result, decimals=-3)
        tm.assert_frame_equal(result, expected)
    def test_wdi_download_monthly(self):
        expected = {
            "COPPER": {
                ("World", "2012M01"): 8040.47,
                ("World", "2011M12"): 7565.48,
                ("World", "2011M11"): 7581.02,
                ("World", "2011M10"): 7394.19,
                ("World", "2011M09"): 8300.14,
                ("World", "2011M08"): 9000.76,
                ("World", "2011M07"): 9650.46,
                ("World", "2011M06"): 9066.85,
                ("World", "2011M05"): 8959.90,
                ("World", "2011M04"): 9492.79,
                ("World", "2011M03"): 9503.36,
                ("World", "2011M02"): 9867.60,
                ("World", "2011M01"): 9555.70,
            }
        }
        expected = pd.DataFrame(expected)
        # Round, to ignore revisions to data.
        expected = np.round(expected, decimals=-3)
        expected = expected.sort_index()
        cntry_codes = "ALL"
        inds = "COPPER"
        result = download(
            country=cntry_codes,
            indicator=inds,
            start=2011,
            end=2012,
            freq="M",
            errors="ignore",
        )
        result = result.sort_index()
        result = np.round(result, decimals=-3)

        expected.index.names = ["country", "year"]
        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds,
                                 countries=cntry_codes,
                                 start=2011,
                                 end=2012,
                                 freq="M",
                                 errors="ignore").read()
        result = result.sort_index()
        result = np.round(result, decimals=-3)
        tm.assert_frame_equal(result, expected)
Example #5
0
    def test_wdi_download_monthly(self):
        expected = {
            'COPPER': {
                ('World', '2012M01'): 8040.47,
                ('World', '2011M12'): 7565.48,
                ('World', '2011M11'): 7581.02,
                ('World', '2011M10'): 7394.19,
                ('World', '2011M09'): 8300.14,
                ('World', '2011M08'): 9000.76,
                ('World', '2011M07'): 9650.46,
                ('World', '2011M06'): 9066.85,
                ('World', '2011M05'): 8959.90,
                ('World', '2011M04'): 9492.79,
                ('World', '2011M03'): 9503.36,
                ('World', '2011M02'): 9867.60,
                ('World', '2011M01'): 9555.70
            }
        }
        expected = pd.DataFrame(expected)
        # Round, to ignore revisions to data.
        expected = np.round(expected, decimals=-3)
        expected = expected.sort_index()
        cntry_codes = 'ALL'
        inds = 'COPPER'
        result = download(country=cntry_codes,
                          indicator=inds,
                          start=2011,
                          end=2012,
                          freq='M',
                          errors='ignore')
        result = result.sort_index()
        result = np.round(result, decimals=-3)

        expected.index.names = ['country', 'year']
        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds,
                                 countries=cntry_codes,
                                 start=2011,
                                 end=2012,
                                 freq='M',
                                 errors='ignore').read()
        result = result.sort_index()
        result = np.round(result, decimals=-3)
        tm.assert_frame_equal(result, expected)
    def test_wdi_download_str(self):

        expected = {'NY.GDP.PCAP.CD': {('Japan', '2004'): 36441.50449394,
                                       ('Japan', '2003'): 33690.93772972,
                                       ('Japan', '2002'): 31235.58818439,
                                       ('Japan', '2001'): 32716.41867489,
                                       ('Japan', '2000'): 37299.64412913}}
        expected = pd.DataFrame(expected)
        # Round, to ignore revisions to data.
        expected = np.round(expected, decimals=-3)
        if PANDAS_0170:
            expected = expected.sort_index()
        else:
            expected = expected.sort()

        cntry_codes = 'JP'
        inds = 'NY.GDP.PCAP.CD'
        result = download(country=cntry_codes, indicator=inds,
                          start=2000, end=2004, errors='ignore')
        if PANDAS_0170:
            result = result.sort_index()
        else:
            result = result.sort()
        result = np.round(result, decimals=-3)

        if PANDAS_0140:
            expected.index.names = ['country', 'year']
        else:
            # prior versions doesn't allow to set multiple names to MultiIndex
            # Thus overwrite it with the result
            expected.index = result.index

        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds, countries=cntry_codes,
                                 start=2000, end=2004, errors='ignore').read()
        if PANDAS_0170:
            result = result.sort_index()
        else:
            result = result.sort()
        result = np.round(result, decimals=-3)
        tm.assert_frame_equal(result, expected)
    def test_wdi_download_quarterly(self):
        expected = {'DT.DOD.PUBS.CD.US': {('Albania', '2012Q1'): 3240539817.18,
                                          ('Albania', '2011Q4'): 3213979715.15,
                                          ('Albania', '2011Q3'): 3187681048.95,
                                          ('Albania', '2011Q2'): 3248041513.86,
                                          ('Albania', '2011Q1'): 3137210567.92}}
        expected = pd.DataFrame(expected)
        # Round, to ignore revisions to data.
        expected = np.round(expected, decimals=-3)
        if PANDAS_0170:
            expected = expected.sort_index()
        else:
            expected = expected.sort()

        cntry_codes = 'ALB'
        inds = 'DT.DOD.PUBS.CD.US'
        result = download(country=cntry_codes, indicator=inds,
                          start=2011, end=2012, freq='Q', errors='ignore')
        if PANDAS_0170:
            result = result.sort_index()
        else:
            result = result.sort()
        result = np.round(result, decimals=-3)

        if PANDAS_0140:
            expected.index.names = ['country', 'year']
        else:
            # prior versions doesn't allow to set multiple names to MultiIndex
            # Thus overwrite it with the result
            expected.index = result.index

        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds, countries=cntry_codes,
                                 start=2011, end=2012, freq='Q', errors='ignore').read()
        if PANDAS_0170:
            result = result.sort_index()
        else:
            result = result.sort()
        result = np.round(result, decimals=-1)
        tm.assert_frame_equal(result, expected)
    def test_wdi_download_quarterly(self):
        code = "DT.DOD.PUBS.CD.US"
        expected = {
            code: {
                ("Albania", "2012Q1"): 3240539817.18,
                ("Albania", "2011Q4"): 3213979715.15,
                ("Albania", "2011Q3"): 3187681048.95,
                ("Albania", "2011Q2"): 3248041513.86,
                ("Albania", "2011Q1"): 3137210567.92,
            }
        }
        expected = pd.DataFrame(expected)
        # Round, to ignore revisions to data.
        expected = np.round(expected, decimals=-3)
        expected = expected.sort_index()
        cntry_codes = "ALB"
        inds = "DT.DOD.PUBS.CD.US"
        result = download(
            country=cntry_codes,
            indicator=inds,
            start=2011,
            end=2012,
            freq="Q",
            errors="ignore",
        )
        result = result.sort_index()
        result = np.round(result, decimals=-3)

        expected.index.names = ["country", "year"]
        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds,
                                 countries=cntry_codes,
                                 start=2011,
                                 end=2012,
                                 freq="Q",
                                 errors="ignore").read()
        result = result.sort_index()
        result = np.round(result, decimals=-1)
        tm.assert_frame_equal(result, expected)
Example #9
0
    def test_wdi_download_quarterly(self):
        code = 'DT.DOD.PUBS.CD.US'
        expected = {
            code: {
                ('Albania', '2012Q1'): 3240539817.18,
                ('Albania', '2011Q4'): 3213979715.15,
                ('Albania', '2011Q3'): 3187681048.95,
                ('Albania', '2011Q2'): 3248041513.86,
                ('Albania', '2011Q1'): 3137210567.92
            }
        }
        expected = pd.DataFrame(expected)
        # Round, to ignore revisions to data.
        expected = np.round(expected, decimals=-3)
        expected = expected.sort_index()
        cntry_codes = 'ALB'
        inds = 'DT.DOD.PUBS.CD.US'
        result = download(country=cntry_codes,
                          indicator=inds,
                          start=2011,
                          end=2012,
                          freq='Q',
                          errors='ignore')
        result = result.sort_index()
        result = np.round(result, decimals=-3)

        expected.index.names = ['country', 'year']
        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds,
                                 countries=cntry_codes,
                                 start=2011,
                                 end=2012,
                                 freq='Q',
                                 errors='ignore').read()
        result = result.sort_index()
        result = np.round(result, decimals=-1)
        tm.assert_frame_equal(result, expected)
Example #10
0
    def test_wdi_download_str(self):

        # These are the expected results, rounded (robust against
        # data revisions in the future).
        expected = {
            'NY.GDP.PCAP.CD': {
                ('Japan', '2004'): 38000.0,
                ('Japan', '2003'): 35000.0,
                ('Japan', '2002'): 32000.0,
                ('Japan', '2001'): 34000.0,
                ('Japan', '2000'): 39000.0
            }
        }
        expected = pd.DataFrame(expected)
        expected = expected.sort_index()

        cntry_codes = 'JP'
        inds = 'NY.GDP.PCAP.CD'
        result = download(country=cntry_codes,
                          indicator=inds,
                          start=2000,
                          end=2004,
                          errors='ignore')
        result = result.sort_index()
        result = np.round(result, decimals=-3)

        expected.index.names = ['country', 'year']
        tm.assert_frame_equal(result, expected)

        result = WorldBankReader(inds,
                                 countries=cntry_codes,
                                 start=2000,
                                 end=2004,
                                 errors='ignore').read()
        result = result.sort_index()
        result = np.round(result, decimals=-3)
        tm.assert_frame_equal(result, expected)