Commit 1d111882 authored by Bruno Duyé's avatar Bruno Duyé

Fix: order dimensions columns by dimensions_codes_order

parent 2a996f88
......@@ -202,9 +202,9 @@ def fetch_series_by_api_link(api_link, max_nb_series=None,
common_columns = ["@frequency", "provider_code", "dataset_code", "dataset_name", "series_code", "series_name",
"original_period", "period", "original_value", "value"]
# Flatten series received from the API (rename some keys of JSON result to match DataFrame organization)
flat_series_list = []
for series in series_list:
# Flatten series received from the API (rename some keys of JSON result to match DataFrame organization).
flat_series = flatten_dbnomics_series(series)
# Add dimensions labels to flat_series
complete_dataset_code = flat_series['provider_code'] + '/' + flat_series['dataset_code'] # ex: "AMECO/ZUTN"
......@@ -239,18 +239,18 @@ def fetch_series_by_api_link(api_link, max_nb_series=None,
def union_sets(sets):
return set.union(*sets)
all_columns = union_sets([set(series.keys()) for series in flat_series_list])
dimension_codes_columns = sorted(all_columns - set(common_columns)) # TODO: use dataset's dimensions ?
# Get dimensions labels and store them in dimensions_labels_columns
# Compute dimensions_labels_columns and dimensions_codes_columns
dimensions_labels_columns = []
dimensions_codes_columns = []
for complete_dataset_code in datasets_dimensions.keys():
for dimension_code in datasets_dimensions[complete_dataset_code]['dimensions_codes_order']:
dimensions_labels_columns = sorted(dimensions_labels_columns)
# In the DataFrame we want to display the dimension columns at the right so we reorder them.
ordered_columns = common_columns + dimension_codes_columns + dimensions_labels_columns
ordered_columns = common_columns + dimensions_codes_columns + dimensions_labels_columns
# Build dataframe
dataframes = (
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment