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

Transform function for AMI EIA861 #647

Merged
merged 4 commits into from
Jun 24, 2020
Merged

Transform function for AMI EIA861 #647

merged 4 commits into from
Jun 24, 2020

Conversation

aesharpe
Copy link
Member

Added Transform function for AMI and updated the totals comparison tool in the notebook.

@aesharpe aesharpe added the eia861 Anything having to do with EIA Form 861 label Jun 23, 2020
@aesharpe aesharpe added this to the PUDL Sprint 17 milestone Jun 23, 2020
@aesharpe aesharpe changed the title Eia861 Transform function for AMI EIA861 Jun 23, 2020
Comment on lines 752 to 753
.dropna(subset=["utility_id_eia"])
.query("utility_id_eia not in (88888, 99999)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking, were these operations actually required for this table? Or is it just cut-and-paste from the sales_eia861 table?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were just cut and pasted from sales.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should probably remove any operations that aren't actually required.

Comment on lines 758 to 783
# Split the table into index, data, and "denormalized" columns for processing:
# Separate customer classes and reported data into a hierarchical index
logger.debug(
"Stacking EIA861 Advanced Metering Infrastructure data columns by customer class.")
data_cols = _filter_customer_cols(clean_ami, CUSTOMER_CLASSES)
data_cols.columns = (
data_cols.columns.str.split("_", n=1, expand=True)
.set_names(["customer_class", None])
)

# Now stack the customer classes into their own categorical column,
data_cols = (
data_cols.stack(level=0, dropna=False)
.reset_index()
)
denorm_cols = (
_filter_non_customer_cols(clean_ami, CUSTOMER_CLASSES)
.reset_index()
)

# Merge the index, data, and denormalized columns back together
tidy_ami = pd.merge(denorm_cols, data_cols, on=idx_cols)

# Remove the now redundant "Total" records -- they can be reconstructed
# from the other customer classes.
tidy_ami = tidy_ami.query("customer_class!='total'")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you notice that we're ending up doing exactly this set of operations for multiple tables, we should probably turn it into a local _helper_function() of some kind.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

)
if dupes.any():
raise AssertionError(
f"Found {dupes.sum()} duplicate rows in the Advanced Metring Infrastructure table, when zero were expected!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think dupes.sum() will add up the values in each of the columns, and return a Series here. Did you maybe mean len(dupes)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm this is one of those weird things where I tried it with len(dupes) on my computer and it was throwing me errors so I changed it but now that I've gone back and tried it again len(dupes) seems to work. I'll change it back.

Copy link
Member

@zaneselvans zaneselvans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only comment is maybe remove the one-liner function to drop total. Otherwise looks great! Hopefully the other customer class dfs are cooperative :)

Comment on lines +563 to +566
def _remove_total_col(df):
"""Remove totals from customer class."""
df = df.query("customer_class!='total'")
return df
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to avoid functions that have only a single statement, unless it's a super opaque thing that becomes more readable by virtue of having a readable function name -- in this case just having a query() or drop() call inline is probably better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call!

@zaneselvans zaneselvans merged commit 3b7f558 into ferc714 Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eia861 Anything having to do with EIA Form 861
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants