Skip to content

Commit

Permalink
Update alembic, improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
e-belfer committed Jun 22, 2023
1 parent 8c94504 commit 0e6edf0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# revision identifiers, used by Alembic.
revision = '9a32db1fbe6e'
down_revision = 'e608f95a3b78'
down_revision = '1ec25c296a6d'
branch_labels = None
depends_on = None

Expand Down
16 changes: 10 additions & 6 deletions src/pudl/transform/ferc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,8 @@ def process_xbrl_metadata(self: Self, xbrl_metadata_json) -> pd.DataFrame:
tbl_meta.xbrl_factoid = tbl_meta.xbrl_factoid.map(xbrl_factoid_name_map)

def rename_calculation_components(calc: str) -> str:
# Apply the rename for the "name" element of all of the calc components.
# Rename all calculation components from their original XBRL factoid names
# to their modified PUDL names.
renamed_calc = [
{
k: self.raw_xbrl_factoid_to_pudl_name(v) if k == "name" else v
Expand Down Expand Up @@ -1982,7 +1983,7 @@ def apply_xbrl_calculation_fixes(
"calc_component_to_replace": {},
"calc_component_new": {
"name": "net_charges_for_retired_plant",
"weight": -1.0,
"weight": 1.0,
},
},
{
Expand Down Expand Up @@ -4770,19 +4771,22 @@ class ElectricPlantDepreciationChangesFerc1TableTransformer(
def process_xbrl_metadata(self, xbrl_metadata_json) -> pd.DataFrame:
"""Transform the metadata to reflect the transformed data.
Warning: The calculations in this table are currently being checked using
Warning: The calculations in this table are currently being corrected using
reconcile_table_calculations(), but they still contain high rates of error.
This function replaces the name of the balance column reported in the XBRL
Instant table with starting_balance / ending_balance since we pull those two
This function replaces the name of the single balance column reported in the
XBRL Instant table with starting_balance / ending_balance. We pull those two
values into their own separate labeled rows, each of which should get the
original metadata for the Instant column. We do this pre-processing before we
metadata from the original column. We do this pre-processing before we
call the main function in order for the calculation fixes and renaming to work
as expected.
"""
new_xbrl_metadata_json = xbrl_metadata_json
# Get instant metadata
instant = pd.json_normalize(xbrl_metadata_json["instant"])
# Duplicate instant metadata, and add starting/ending suffix
instant = pd.concat([instant] * 2).reset_index(drop=True)
instant["name"] = instant["name"] + ["_starting_balance", "_ending_balance"]
# Return to JSON format in order to continue processing
new_xbrl_metadata_json["instant"] = json.loads(
instant.to_json(orient="records")
)
Expand Down
4 changes: 3 additions & 1 deletion src/pudl/transform/params/ferc1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3970,7 +3970,9 @@
},
"reconcile_table_calculations": {
"column_to_check": "dollar_value",
"calculation_tolerance": 0.2,
# Note: this table does not currently get exploded. It will require
# additional debugging at a later date.
"calculation_tolerance": 0.4,
"subtotal_column": "depreciation_type",
},
},
Expand Down

0 comments on commit 0e6edf0

Please sign in to comment.