@@ -883,15 +883,15 @@ def validate_series_object(series_object):
883
883
884
884
def generate_payload_for_v2_area_weighting (
885
885
series : Dict [str , int ],
886
- region_id : int ,
886
+ region_ids : List [ int ] ,
887
887
weights : Optional [List [Dict [str , int ]]] = None ,
888
888
weight_names : Optional [List [str ]] = None ,
889
889
start_date : Optional [str ] = None ,
890
890
end_date : Optional [str ] = None ,
891
891
method : Optional [str ] = "sum" ,
892
892
):
893
893
payload = {
894
- "region_id " : region_id ,
894
+ "region_ids " : region_ids ,
895
895
"method" : method ,
896
896
}
897
897
@@ -926,6 +926,12 @@ def generate_payload_for_v2_area_weighting(
926
926
927
927
928
928
def format_v2_area_weighting_response (response_content : Dict [str , Any ]) -> pd .DataFrame :
929
+ DATETIME_COL_MAPPINGS = {
930
+ "start_date" : "timestamp" , # add start_date col which is equivalent to end_date
931
+ "end_date" : "timestamp" ,
932
+ "available_date" : "available_timestamp" ,
933
+ }
934
+
929
935
try :
930
936
data_points = response_content ["data_points" ]
931
937
weighted_series_df = pd .DataFrame (data_points )
@@ -934,14 +940,10 @@ def format_v2_area_weighting_response(response_content: Dict[str, Any]) -> pd.Da
934
940
return weighted_series_df
935
941
936
942
# convert unix timestamps and rename date cols
937
- datetime_col_mappings = {
938
- "start_date" : "timestamp" , # add start_date col which is equivalent to end_date
939
- "end_date" : "timestamp" ,
940
- "available_date" : "available_timestamp" ,
941
- }
942
- for new_col , col in datetime_col_mappings .items ():
943
- weighted_series_df [new_col ] = pd .to_datetime (weighted_series_df [col ], unit = 's' ).dt .strftime ('%Y-%m-%d' )
944
- weighted_series_df = weighted_series_df .drop (columns = datetime_col_mappings .values ())
943
+ for new_col , col in DATETIME_COL_MAPPINGS .items ():
944
+ if col in weighted_series_df .columns :
945
+ weighted_series_df [new_col ] = pd .to_datetime (weighted_series_df [col ], unit = 's' ).dt .strftime ('%Y-%m-%d' )
946
+ weighted_series_df = weighted_series_df .drop (columns = DATETIME_COL_MAPPINGS .values (), errors = "ignore" )
945
947
946
948
# append selected fields of series metadata
947
949
for key in ['item_id' , 'metric_id' , 'frequency_id' , 'unit_id' , 'source_id' ]:
@@ -959,7 +961,7 @@ def get_area_weighted_series_df(
959
961
access_token : str ,
960
962
api_host : str ,
961
963
series : Dict [str , int ],
962
- region_id : int ,
964
+ region_ids : List [ int ] ,
963
965
weights : Optional [List [Dict [str , int ]]] = None ,
964
966
weight_names : Optional [List [str ]] = None ,
965
967
start_date : Optional [str ] = None ,
@@ -968,7 +970,7 @@ def get_area_weighted_series_df(
968
970
) -> pd .DataFrame :
969
971
payload = generate_payload_for_v2_area_weighting (
970
972
series ,
971
- region_id ,
973
+ region_ids ,
972
974
weights ,
973
975
weight_names ,
974
976
start_date ,
0 commit comments