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

Data source/pa #111

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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
2 changes: 1 addition & 1 deletion src/utils/table.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Address:
transactor: Transactor

Membership:
required_attribute:
required_attributes:
- member_id
- organization_id
attributes:
Expand Down
8 changes: 7 additions & 1 deletion src/utils/yamltable.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(self, data_schema: dict, table_type: str): # noqa ANN204
self.table_type = table_type
self.data_schema = data_schema
self._child_types_are_separate = None
self._child_types = None
self._parent_type = None
self._attributes = None
self._repeating_columns = None
Expand Down Expand Up @@ -206,6 +207,8 @@ def child_types_are_separate(self) -> bool:
@property
def child_types(self) -> list:
"""Types that inherit attributes from the current type"""
if self._child_types is None:
self._child_types = self.data_schema[self.table_type].get("child_types", [])
return self._child_types

@property
Expand Down Expand Up @@ -436,6 +439,7 @@ def _add_forward_relation_to_foreign_table(
] == forward_relation and table_type in [
forward_relation_type,
schema.schema[forward_relation_type].parent_type,
*schema.schema[forward_relation_type].child_types,
]:
# this means the derivative table requires a column linking back to
# the current table
Expand All @@ -449,7 +453,7 @@ def _add_forward_relation_to_foreign_table(
table.loc[
relevant_rows_mask,
backlink_column,
] = table.loc[relevant_rows_mask].index
] = table.loc[relevant_rows_mask]["id"]
foreign_columns_in_base_table.append(backlink_column)
foreign_columns_in_foreign_table.append(required_attribute)
return table, foreign_columns_in_base_table, foreign_columns_in_foreign_table
Expand Down Expand Up @@ -553,6 +557,8 @@ def _normalize_table_completely(
].items()
if not column.startswith(forward_relation_column)
}
# this is where the heavy lifting is done and a new foreign table
# is created derived from the columns that did not belong in base table
active_table, foreign_table = _split_prefixed_columns(
active_table,
table_type,
Expand Down
Loading