Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder columns to match sql #865

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions data_updates/Python/iati_transaction_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

A_DTYPES = {
'iati_identifier': 'object',
'x_activity_number': 'float64',
'reporting_org_ref': 'object',
'reporting_org_narrative': 'object',
'reporting_org_secondary_reporter': 'object',
Expand All @@ -26,13 +25,13 @@
'x_reporting_org_type': 'object',
'dac_policy_marker_code': 'object',
'dac_policy_marker_significance': 'object',
'x_activity_number': 'float64',
'package_id': 'object',
'last_modified': 'object',
}
A_NUMERIC_DTYPES = [column_name for column_name, dtype in A_DTYPES.items() if dtype not in ["object", "bool_"]]
T_DTYPES = {
'iati_identifier': 'object',
'x_activity_number': 'float64',
'x_transaction_number': 'float64',
'x_original_transaction_value': 'float64',
'x_original_transaction_value_usd': 'float64',
Expand Down Expand Up @@ -86,6 +85,7 @@
'x_covid': 'bool_',
'x_donor_transaction_type': 'object',
'x_original_transaction_value_USDm': 'float64',
'x_activity_number': 'float64',
'package_id': 'object',
}
T_NUMERIC_DTYPES = [column_name for column_name, dtype in T_DTYPES.items() if dtype not in ["object", "bool_"]]
Expand Down Expand Up @@ -167,8 +167,8 @@ def convert_usd(value, year, currency, ratedf):
# A class that will hold the flattening function and dictionary definitions
class IatiFlat(object):
def __init__(self):
self.activity_header = ["iati_identifier", "x_activity_number", "reporting_org_ref", "reporting_org_narrative", "reporting_org_secondary_reporter", "reporting_org_type_code", "title_narrative", "collaboration_type", "description_narrative", "humanitarian", "humanitarian_scope_narrative", "x_hum_emergency_code", "x_hum_appeal_code", "funding_orgs", "accountable_orgs", "extending_orgs", "implementing_orgs", "tag_narrative", "tag_vocabulary", "tag_code", "x_reporting_org_type", "dac_policy_marker_code", "dac_policy_marker_significance"]
self.transaction_header = ["iati_identifier", "x_activity_number", "x_transaction_number", "x_original_transaction_value", "x_original_transaction_value_usd", "x_country_code", "x_country", "x_country_percentage", "x_recipient_number", "x_recipient_code", "x_recipient", "x_recipient_percentage", "x_recipient_type", "x_recipient_vocabulary","x_recipient_transaction_value", "x_recipient_transaction_value_usd", "x_sector_number", "x_sector_vocabulary", "x_vocabulary_number", "x_sector_code", "x_sector_percentage", "x_dac3_sector_code", "transaction_type_code", "x_transaction_date", "x_transaction_year", "x_currency", "x_transaction_value", "x_transaction_value_usd", "x_flow_type_code", "x_finance_type_code", "x_mod_aid_type_vocabulary", "x_mod_aid_type_code", "x_dac_aid_type_code", "x_tied_status_code", "transaction_disbursement_channel_code", "transaction_description_narrative", "transaction_humanitarian", "transaction_provider_org_narrative", "transaction_provider_org_provider_activity_id", "transaction_provider_org_ref", "transaction_provider_org_type", "transaction_receiver_org_narrative", "transaction_receiver_org_receiver_activity_id", "transaction_receiver_org_ref", "transaction_receiver_org_type", "transaction_ref", "x_transaction_type", "x_finance_type", "x_aid_type", "x_dac3_sector", "x_di_sector", "x_yyyymm", "x_covid", "x_donor_transaction_type", "x_original_transaction_value_USDm"]
self.activity_header = ["iati_identifier", "reporting_org_ref", "reporting_org_narrative", "reporting_org_secondary_reporter", "reporting_org_type_code", "title_narrative", "collaboration_type", "description_narrative", "humanitarian", "humanitarian_scope_narrative", "x_hum_emergency_code", "x_hum_appeal_code", "funding_orgs", "accountable_orgs", "extending_orgs", "implementing_orgs", "tag_narrative", "tag_vocabulary", "tag_code", "x_reporting_org_type", "dac_policy_marker_code", "dac_policy_marker_significance", "x_activity_number"]
self.transaction_header = ["iati_identifier", "x_transaction_number", "x_original_transaction_value", "x_original_transaction_value_usd", "x_country_code", "x_country", "x_country_percentage", "x_recipient_number", "x_recipient_code", "x_recipient", "x_recipient_percentage", "x_recipient_type", "x_recipient_vocabulary","x_recipient_transaction_value", "x_recipient_transaction_value_usd", "x_sector_number", "x_sector_vocabulary", "x_vocabulary_number", "x_sector_code", "x_sector_percentage", "x_dac3_sector_code", "transaction_type_code", "x_transaction_date", "x_transaction_year", "x_currency", "x_transaction_value", "x_transaction_value_usd", "x_flow_type_code", "x_finance_type_code", "x_mod_aid_type_vocabulary", "x_mod_aid_type_code", "x_dac_aid_type_code", "x_tied_status_code", "transaction_disbursement_channel_code", "transaction_description_narrative", "transaction_humanitarian", "transaction_provider_org_narrative", "transaction_provider_org_provider_activity_id", "transaction_provider_org_ref", "transaction_provider_org_type", "transaction_receiver_org_narrative", "transaction_receiver_org_receiver_activity_id", "transaction_receiver_org_ref", "transaction_receiver_org_type", "transaction_ref", "x_transaction_type", "x_finance_type", "x_aid_type", "x_dac3_sector", "x_di_sector", "x_yyyymm", "x_covid", "x_donor_transaction_type", "x_original_transaction_value_USDm", "x_activity_number"]
self.dictionaries = {}
# Defaults, can be overwritten with next function
self.dictionaries["ratedf"] = ratedf
Expand Down Expand Up @@ -851,7 +851,7 @@ def flatten_activities(self, root):
x_reporting_org_type = ""
x_reporting_org_type = recode_if_not_none(reporting_org_type_code, self.dictionaries["organisation_type"])

activity_row = [iati_identifier, x_activity_number, reporting_org_ref, reporting_org_narrative, reporting_org_secondary_reporter, reporting_org_type_code, title_narrative, collaboration_type, description_narrative, humanitarian, humanitarian_scope_narrative, x_hum_emergency_code, x_hum_appeal_code, funding_orgs, accountable_orgs, extending_orgs, implementing_orgs, tag_narrative, tag_vocabulary, tag_code, x_reporting_org_type, dac_policy_marker_code, dac_policy_marker_significance]
activity_row = [iati_identifier, reporting_org_ref, reporting_org_narrative, reporting_org_secondary_reporter, reporting_org_type_code, title_narrative, collaboration_type, description_narrative, humanitarian, humanitarian_scope_narrative, x_hum_emergency_code, x_hum_appeal_code, funding_orgs, accountable_orgs, extending_orgs, implementing_orgs, tag_narrative, tag_vocabulary, tag_code, x_reporting_org_type, dac_policy_marker_code, dac_policy_marker_significance, x_activity_number]
activity_output.append(activity_row)

has_transactions = "transaction" in child_tags
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def flatten_activities(self, root):
x_country_code = x_recipient_code
x_country = x_recipient
x_country_percentage = x_recipient_percentage
row = [iati_identifier, x_activity_number, x_transaction_number, x_original_transaction_value, x_original_transaction_value_usd, x_country_code, x_country, x_country_percentage, x_recipient_number, x_recipient_code, x_recipient, x_recipient_percentage, x_recipient_type, x_recipient_vocabulary, x_recipient_transaction_value, x_recipient_transaction_value_usd, x_sector_number, x_sector_vocabulary, x_vocabulary_number, x_sector_code, x_sector_percentage, x_dac3_sector_code, transaction_type_code, x_transaction_date, x_transaction_year, x_currency, x_transaction_value, x_transaction_value_usd, x_flow_type_code, x_finance_type_code, x_mod_aid_type_vocabulary, x_mod_aid_type_code, x_dac_aid_type_code, x_tied_status_code, transaction_disbursement_channel_code, transaction_description_narrative, transaction_humanitarian, transaction_provider_org_narrative, transaction_provider_org_provider_activity_id, transaction_provider_org_ref, transaction_provider_org_type, transaction_receiver_org_narrative, transaction_receiver_org_receiver_activity_id, transaction_receiver_org_ref, transaction_receiver_org_type, transaction_ref, x_transaction_type, x_finance_type, x_aid_type, x_dac3_sector, x_di_sector, x_yyyymm, x_covid, x_donor_transaction_type, x_original_transaction_value_USDm]
row = [iati_identifier, x_transaction_number, x_original_transaction_value, x_original_transaction_value_usd, x_country_code, x_country, x_country_percentage, x_recipient_number, x_recipient_code, x_recipient, x_recipient_percentage, x_recipient_type, x_recipient_vocabulary, x_recipient_transaction_value, x_recipient_transaction_value_usd, x_sector_number, x_sector_vocabulary, x_vocabulary_number, x_sector_code, x_sector_percentage, x_dac3_sector_code, transaction_type_code, x_transaction_date, x_transaction_year, x_currency, x_transaction_value, x_transaction_value_usd, x_flow_type_code, x_finance_type_code, x_mod_aid_type_vocabulary, x_mod_aid_type_code, x_dac_aid_type_code, x_tied_status_code, transaction_disbursement_channel_code, transaction_description_narrative, transaction_humanitarian, transaction_provider_org_narrative, transaction_provider_org_provider_activity_id, transaction_provider_org_ref, transaction_provider_org_type, transaction_receiver_org_narrative, transaction_receiver_org_receiver_activity_id, transaction_receiver_org_ref, transaction_receiver_org_type, transaction_ref, x_transaction_type, x_finance_type, x_aid_type, x_dac3_sector, x_di_sector, x_yyyymm, x_covid, x_donor_transaction_type, x_original_transaction_value_USDm, x_activity_number]
transaction_output.append(row)
# Reset sector-split specific defaults
x_sector_number = 1
Expand All @@ -1178,7 +1178,7 @@ def flatten_activities(self, root):
x_country_code = x_recipient_code
x_country = x_recipient
x_country_percentage = x_recipient_percentage
row = [iati_identifier, x_activity_number, x_transaction_number, x_original_transaction_value, x_original_transaction_value_usd, x_country_code, x_country, x_country_percentage, x_recipient_number, x_recipient_code, x_recipient, x_recipient_percentage, x_recipient_type, x_recipient_vocabulary, x_recipient_transaction_value, x_recipient_transaction_value_usd, x_sector_number, x_sector_vocabulary, x_vocabulary_number, x_sector_code, x_sector_percentage, x_dac3_sector_code, transaction_type_code, x_transaction_date, x_transaction_year, x_currency, x_transaction_value, x_transaction_value_usd, x_flow_type_code, x_finance_type_code, x_mod_aid_type_vocabulary, x_mod_aid_type_code, x_dac_aid_type_code, x_tied_status_code, transaction_disbursement_channel_code, transaction_description_narrative, transaction_humanitarian, transaction_provider_org_narrative, transaction_provider_org_provider_activity_id, transaction_provider_org_ref, transaction_provider_org_type, transaction_receiver_org_narrative, transaction_receiver_org_receiver_activity_id, transaction_receiver_org_ref, transaction_receiver_org_type, transaction_ref, x_transaction_type, x_finance_type, x_aid_type, x_dac3_sector, x_di_sector, x_yyyymm, x_covid, x_donor_transaction_type, x_original_transaction_value_USDm]
row = [iati_identifier, x_transaction_number, x_original_transaction_value, x_original_transaction_value_usd, x_country_code, x_country, x_country_percentage, x_recipient_number, x_recipient_code, x_recipient, x_recipient_percentage, x_recipient_type, x_recipient_vocabulary, x_recipient_transaction_value, x_recipient_transaction_value_usd, x_sector_number, x_sector_vocabulary, x_vocabulary_number, x_sector_code, x_sector_percentage, x_dac3_sector_code, transaction_type_code, x_transaction_date, x_transaction_year, x_currency, x_transaction_value, x_transaction_value_usd, x_flow_type_code, x_finance_type_code, x_mod_aid_type_vocabulary, x_mod_aid_type_code, x_dac_aid_type_code, x_tied_status_code, transaction_disbursement_channel_code, transaction_description_narrative, transaction_humanitarian, transaction_provider_org_narrative, transaction_provider_org_provider_activity_id, transaction_provider_org_ref, transaction_provider_org_type, transaction_receiver_org_narrative, transaction_receiver_org_receiver_activity_id, transaction_receiver_org_ref, transaction_receiver_org_type, transaction_ref, x_transaction_type, x_finance_type, x_aid_type, x_dac3_sector, x_di_sector, x_yyyymm, x_covid, x_donor_transaction_type, x_original_transaction_value_USDm, x_activity_number]
transaction_output.append(row)
# Reset missing sector-split specific defaults
x_transaction_value = transaction_value
Expand Down Expand Up @@ -1227,7 +1227,7 @@ def flatten_activities(self, root):
x_country_code = x_recipient_code
x_country = x_recipient
x_country_percentage = x_recipient_percentage
row = [iati_identifier, x_activity_number, x_transaction_number, x_original_transaction_value, x_original_transaction_value_usd, x_country_code, x_country, x_country_percentage, x_recipient_number, x_recipient_code, x_recipient, x_recipient_percentage, x_recipient_type, x_recipient_vocabulary, x_recipient_transaction_value, x_recipient_transaction_value_usd, x_sector_number, x_sector_vocabulary, x_vocabulary_number, x_sector_code, x_sector_percentage, x_dac3_sector_code, transaction_type_code, x_transaction_date, x_transaction_year, x_currency, x_transaction_value, x_transaction_value_usd, x_flow_type_code, x_finance_type_code, x_mod_aid_type_vocabulary, x_mod_aid_type_code, x_dac_aid_type_code, x_tied_status_code, transaction_disbursement_channel_code, transaction_description_narrative, transaction_humanitarian, transaction_provider_org_narrative, transaction_provider_org_provider_activity_id, transaction_provider_org_ref, transaction_provider_org_type, transaction_receiver_org_narrative, transaction_receiver_org_receiver_activity_id, transaction_receiver_org_ref, transaction_receiver_org_type, transaction_ref, x_transaction_type, x_finance_type, x_aid_type, x_dac3_sector, x_di_sector, x_yyyymm, x_covid, x_donor_transaction_type, x_original_transaction_value_USDm]
row = [iati_identifier, x_transaction_number, x_original_transaction_value, x_original_transaction_value_usd, x_country_code, x_country, x_country_percentage, x_recipient_number, x_recipient_code, x_recipient, x_recipient_percentage, x_recipient_type, x_recipient_vocabulary, x_recipient_transaction_value, x_recipient_transaction_value_usd, x_sector_number, x_sector_vocabulary, x_vocabulary_number, x_sector_code, x_sector_percentage, x_dac3_sector_code, transaction_type_code, x_transaction_date, x_transaction_year, x_currency, x_transaction_value, x_transaction_value_usd, x_flow_type_code, x_finance_type_code, x_mod_aid_type_vocabulary, x_mod_aid_type_code, x_dac_aid_type_code, x_tied_status_code, transaction_disbursement_channel_code, transaction_description_narrative, transaction_humanitarian, transaction_provider_org_narrative, transaction_provider_org_provider_activity_id, transaction_provider_org_ref, transaction_provider_org_type, transaction_receiver_org_narrative, transaction_receiver_org_receiver_activity_id, transaction_receiver_org_ref, transaction_receiver_org_type, transaction_ref, x_transaction_type, x_finance_type, x_aid_type, x_dac3_sector, x_di_sector, x_yyyymm, x_covid, x_donor_transaction_type, x_original_transaction_value_USDm, x_activity_number]
transaction_output.append(row)
# Reset sector-split specific defaults
x_sector_number = 1
Expand All @@ -1246,7 +1246,7 @@ def flatten_activities(self, root):
x_country_code = x_recipient_code
x_country = x_recipient
x_country_percentage = x_recipient_percentage
row = [iati_identifier, x_activity_number, x_transaction_number, x_original_transaction_value, x_original_transaction_value_usd, x_country_code, x_country, x_country_percentage, x_recipient_number, x_recipient_code, x_recipient, x_recipient_percentage, x_recipient_type, x_recipient_vocabulary, x_recipient_transaction_value, x_recipient_transaction_value_usd, x_sector_number, x_sector_vocabulary, x_vocabulary_number, x_sector_code, x_sector_percentage, x_dac3_sector_code, transaction_type_code, x_transaction_date, x_transaction_year, x_currency, x_transaction_value, x_transaction_value_usd, x_flow_type_code, x_finance_type_code, x_mod_aid_type_vocabulary, x_mod_aid_type_code, x_dac_aid_type_code, x_tied_status_code, transaction_disbursement_channel_code, transaction_description_narrative, transaction_humanitarian, transaction_provider_org_narrative, transaction_provider_org_provider_activity_id, transaction_provider_org_ref, transaction_provider_org_type, transaction_receiver_org_narrative, transaction_receiver_org_receiver_activity_id, transaction_receiver_org_ref, transaction_receiver_org_type, transaction_ref, x_transaction_type, x_finance_type, x_aid_type, x_dac3_sector, x_di_sector, x_yyyymm, x_covid, x_donor_transaction_type, x_original_transaction_value_USDm]
row = [iati_identifier, x_transaction_number, x_original_transaction_value, x_original_transaction_value_usd, x_country_code, x_country, x_country_percentage, x_recipient_number, x_recipient_code, x_recipient, x_recipient_percentage, x_recipient_type, x_recipient_vocabulary, x_recipient_transaction_value, x_recipient_transaction_value_usd, x_sector_number, x_sector_vocabulary, x_vocabulary_number, x_sector_code, x_sector_percentage, x_dac3_sector_code, transaction_type_code, x_transaction_date, x_transaction_year, x_currency, x_transaction_value, x_transaction_value_usd, x_flow_type_code, x_finance_type_code, x_mod_aid_type_vocabulary, x_mod_aid_type_code, x_dac_aid_type_code, x_tied_status_code, transaction_disbursement_channel_code, transaction_description_narrative, transaction_humanitarian, transaction_provider_org_narrative, transaction_provider_org_provider_activity_id, transaction_provider_org_ref, transaction_provider_org_type, transaction_receiver_org_narrative, transaction_receiver_org_receiver_activity_id, transaction_receiver_org_ref, transaction_receiver_org_type, transaction_ref, x_transaction_type, x_finance_type, x_aid_type, x_dac3_sector, x_di_sector, x_yyyymm, x_covid, x_donor_transaction_type, x_original_transaction_value_USDm, x_activity_number]
transaction_output.append(row)
# Reset missing sector-split specific defaults
x_transaction_value = transaction_value
Expand Down