Skip to content

Commit

Permalink
fix id handling for PA finance data source
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorspreadbury committed Sep 30, 2024
1 parent 74bbd33 commit 29a5d79
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/utils/finance/states/pennsylvania.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ def id_columns_to_standardize(self) -> dict: # noqa D102

def _get_additional_columns(self) -> None:
super()._get_additional_columns()
# add PA as election state to rows that have election info
# add PA as election state to rows that have election info other than year
election_columns = [
col for col in self.table.columns if col.startswith("election_result--")
col
for col in self.table.columns
if col.startswith("election_result--") and not col.endswith("year")
]
election_info_mask = self.table[election_columns].notna().any(axis=1)
self.table.loc[election_info_mask, "election_result--election--state"] = "PA"
Expand Down Expand Up @@ -203,7 +205,7 @@ def id_columns_to_standardize(self) -> dict: # noqa D102
return {
"donor_id": [],
"recipient_id": ["recipient--election_result--candidate_id"],
"reported_election_id": ["recipient--election_result--election--id"],
"reported_election--id": ["recipient--election_result--election--id"],
}

@property
Expand All @@ -219,9 +221,10 @@ def column_details(self) -> pd.DataFrame: # noqa D102
def _get_additional_columns(self) -> None:
super()._get_additional_columns()

self.table.loc[:, "reported_election--year"] = self.table.loc[
:, "recipient--election_result--election--year"
]
self.table.loc[:, "recipient--election_result--election--year"] = (
self.table.loc[:, "reported_election--year"]
)
self.table.loc[:, "reported_election--id"] = None
self.table.loc[:, "recipient--election_result--candidate_id"] = None
self.table.loc[:, "recipient--election_result--election--id"] = None

Expand Down Expand Up @@ -308,8 +311,8 @@ def id_columns_to_standardize(self) -> dict: # noqa D102
def _get_additional_columns(self) -> None:
super()._get_additional_columns()

self.table.loc[:, "reported_election--year"] = self.table.loc[
:, "donor--election_result--election--year"
self.table.loc[:, "donor--election_result--election--year"] = self.table.loc[
:, "reported_election--year"
]
self.table.loc[:, "donor--election_result--candidate_id"] = None
self.table.loc[:, "donor--election_result--election_id"] = None
Expand Down

0 comments on commit 29a5d79

Please sign in to comment.