Пример #1
0
def get_data(path, rows, columns, filters=None, measure=None):
    if isinstance(rows, str):
        rows = [rows]
    if isinstance(columns, str):
        columns = [columns]
    if isinstance(filters, str):
        filters = [filters]

    params = dict(row=','.join(rows), column=','.join(columns))
    if filters:
        params['filter'] = ','.join(filters)

    resp = requests.get(
        BASE_URL + path + '.json',
        params=params,
        headers=REQUESTS_HEADERS,
    )
    resp.raise_for_status()

    out = resp.json(object_pairs_hook=OrderedDict)['dataset']
    out['id'] = out['dimension']['id']
    for dim_name in out['id']:
        out['dimension'][dim_name]['label'] = None

    df = pyjstat.generate_df(out, 'label')
    return df
Пример #2
0
 def test_generate_df_with_id(self):
     """Test pyjstat generate_df() using id as parameter."""
     data_df = pyjstat.generate_df(self.oecd_datasets['oecd'], 'id')
     line_thirty = ['UNR', 'BE', '2009', 7.891892855]
     dimensions = pyjstat.get_dimensions(self.oecd_datasets['oecd'], 'id')
     self.assertTrue(set(data_df.columns.values[:-1]) == set(dimensions[1]))
     self.assertTrue(set(data_df.iloc[30].values) == set(line_thirty))
Пример #3
0
    def test_generate_df_with_id(self):
        """ Test pyjstat generate_df() using id as parameter"""

        data_df = pyjstat.generate_df(self.oecd_datasets["oecd"], "id")
        line_thirty = ["UNR", "BE", "2009", 7.891892855]
        dimensions = pyjstat.get_dimensions(self.oecd_datasets["oecd"], "id")
        self.assertTrue(set(data_df.columns.values[:-1]) == set(dimensions[1]))
        self.assertTrue(set(data_df.iloc[30].values) == set(line_thirty))
Пример #4
0
    def test_generate_df_with_label(self):
        """ Test pyjstat generate_df() using label as parameter"""

        data_df = pyjstat.generate_df(self.oecd_datasets["oecd"], "label")
        line_thirty = ["unemployment rate", "Belgium", "2009", 7.891892855]
        dimensions = pyjstat.get_dimensions(self.oecd_datasets["oecd"], "label")
        self.assertTrue(set(data_df.columns.values[:-1]) == set(dimensions[1]))
        self.assertTrue(set(data_df.iloc[30].values) == set(line_thirty))
Пример #5
0
 def test_generate_df_with_label(self):
     """Test pyjstat generate_df() using label as parameter."""
     data_df = pyjstat.generate_df(self.oecd_datasets['oecd'], 'label')
     line_thirty = ['unemployment rate', 'Belgium', '2009', 7.891892855]
     dimensions = pyjstat.get_dimensions(self.oecd_datasets['oecd'],
                                         'label')
     self.assertTrue(set(data_df.columns.values[:-1]) == set(dimensions[1]))
     self.assertTrue(set(data_df.iloc[30].values) == set(line_thirty))
Пример #6
0
    def test_generate_df_with_id(self):
        """ Test pyjstat generate_df() using id as parameter"""

        data_df = pyjstat.generate_df(self.oecd_datasets['oecd'], 'id')
        line_thirty = ['UNR', 'BE', 2009, 7.891892855]
        dimensions = pyjstat.get_dimensions(self.oecd_datasets['oecd'], 'id')
        self.assertTrue(set(data_df.columns.values[:-1]) ==
                        set(dimensions[1]))
        self.assertTrue(set(data_df.iloc[30].values) ==
                        set(line_thirty))
Пример #7
0
    def test_generate_df_with_label(self):
        """ Test pyjstat generate_df() using label as parameter"""

        data_df = pyjstat.generate_df(self.oecd_datasets['oecd'], 'label')
        line_thirty = ['Unemployment rate', 'Belgium', 2009, 7.891892855]
        dimensions = pyjstat.get_dimensions(self.oecd_datasets['oecd'],
                                            'label')
        self.assertTrue(set(data_df.columns.values[:-1]) ==
                        set(dimensions[1]))
        self.assertTrue(set(data_df.iloc[30].values) ==
                        set(line_thirty))