Ejemplo n.º 1
0
    def _read_one_data(self, url, params):
        resp_dsd = self._get_response(self.dsd_url)
        dsd = _read_sdmx_dsd(resp_dsd.content)

        resp = self._get_response(url)
        data = read_sdmx(resp.content, dsd=dsd)

        try:
            data.index = pd.to_datetime(data.index)
            data = data.sort_index()
            data = data.truncate(self.start, self.end)
        except ValueError:
            pass
        return data
Ejemplo n.º 2
0
def test_tourism(dirpath):
    # Eurostat
    # Employed doctorate holders in non managerial and non professional
    # occupations by fields of science (%)
    dsd = _read_sdmx_dsd(os.path.join(dirpath, "sdmx", "DSD_cdh_e_fos.xml"))
    df = read_sdmx(os.path.join(dirpath, "sdmx", "cdh_e_fos.xml"), dsd=dsd)

    assert isinstance(df, pd.DataFrame)
    assert df.shape == (2, 336)

    df = df["Percentage"]["Total"]["Natural sciences"]
    df = df[["Norway", "Poland", "Portugal", "Russia"]]

    exp_col = pd.MultiIndex.from_product(
        [["Norway", "Poland", "Portugal", "Russia"], ["Annual"]], names=["GEO", "FREQ"]
    )
    exp_idx = pd.DatetimeIndex(["2009", "2006"], name="TIME_PERIOD")

    values = np.array([[20.38, 25.1, 27.77, 38.1], [25.49, np.nan, 39.05, np.nan]])
    expected = pd.DataFrame(values, index=exp_idx, columns=exp_col)
    tm.assert_frame_equal(df, expected)
Ejemplo n.º 3
0
def test_tourism(dirpath):
    # Eurostat
    # Employed doctorate holders in non managerial and non professional
    # occupations by fields of science (%)
    dsd = _read_sdmx_dsd(os.path.join(dirpath, 'sdmx', 'DSD_cdh_e_fos.xml'))
    df = read_sdmx(os.path.join(dirpath, 'sdmx', 'cdh_e_fos.xml'), dsd=dsd)

    assert isinstance(df, pd.DataFrame)
    assert df.shape == (2, 336)

    df = df['Percentage']['Total']['Natural sciences']
    df = df[['Norway', 'Poland', 'Portugal', 'Russia']]

    exp_col = pd.MultiIndex.from_product(
        [['Norway', 'Poland', 'Portugal', 'Russia'], ['Annual']],
        names=['GEO', 'FREQ'])
    exp_idx = pd.DatetimeIndex(['2009', '2006'], name='TIME_PERIOD')

    values = np.array([[20.38, 25.1, 27.77, 38.1],
                       [25.49, np.nan, 39.05, np.nan]])
    expected = pd.DataFrame(values, index=exp_idx, columns=exp_col)
    tm.assert_frame_equal(df, expected)
Ejemplo n.º 4
0
    def test_tourism(self):
        # Eurostat
        # Employed doctorate holders in non managerial and non professional
        # occupations by fields of science (%)
        dsd = _read_sdmx_dsd(os.path.join(self.dirpath, 'sdmx', 'DSD_cdh_e_fos.xml'))
        df = read_sdmx(os.path.join(self.dirpath, 'sdmx', 'cdh_e_fos.xml'), dsd=dsd)

        self.assertTrue(isinstance(df, pd.DataFrame))
        self.assertEqual(df.shape, (2, 336))

        df = df['Percentage']['Total']['Natural sciences']
        df = df[['Norway', 'Poland', 'Portugal', 'Russia']]

        exp_col = pd.MultiIndex.from_product([['Norway', 'Poland', 'Portugal', 'Russia'],
                                              ['Annual']],
                                             names=['GEO', 'FREQ'])
        exp_idx = pd.DatetimeIndex(['2009', '2006'], name='TIME_PERIOD')

        values = np.array([[20.38, 25.1, 27.77, 38.1],
                           [25.49, np.nan, 39.05, np.nan]])
        expected = pd.DataFrame(values, index=exp_idx, columns=exp_col)
        tm.assert_frame_equal(df, expected)