Skip to content

Commit

Permalink
chore: replace infs with nans
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdadams committed Nov 5, 2024
1 parent 2db6f5d commit d4b3954
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/wmrc/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Calender_Year__c to create dataframes of the reports that will be used to update the AGOL feature services.
"""

import numpy as np
import pandas as pd

try:
Expand Down Expand Up @@ -233,6 +234,7 @@ def recovery_rates_by_tonnage(records: helpers.SalesForceRecords) -> pd.Series:
)
)

clean_rates.replace([np.inf, -np.inf], np.nan, inplace=True) #: Can arise from division by np.nan
clean_rates.name = "annual_recycling_uncontaminated_rate"
clean_rates.index.name = "data_year"
clean_rates.index = clean_rates.index.map(helpers.convert_to_int)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,31 @@ def test_recovery_rates_by_tonnage_happy_path(self, mocker):

pd.testing.assert_series_equal(output_series, test_df)

def test_recovery_rates_by_tonnage_replaces_inf_with_zero(self, mocker):
records = mocker.Mock()
records.df = pd.DataFrame(
{
"Calendar_Year__c": [2022, 2022, 2023, 2023],
"Out_of_State__c": [0, 0, 0, 0],
"Municipal_Solid_Waste__c": [100, 100, 100, 100],
"Annual_Recycling_Contamination_Rate__c": [np.nan, np.nan, 50, 50],
"Combined_Total_of_Material_Recycled__c": [50, 100, 50, 40],
}
)

output_series = summarize.recovery_rates_by_tonnage(records)

test_df = pd.Series(
{
2022: np.nan,
2023: 50.0,
},
name="annual_recycling_uncontaminated_rate",
)
test_df.index.name = "data_year"

pd.testing.assert_series_equal(output_series, test_df)

def test_recovery_rates_by_tonnage_uses_out_of_state_modifier(self, mocker):
records = mocker.Mock()
records.df = pd.DataFrame(
Expand Down

0 comments on commit d4b3954

Please sign in to comment.