Skip to content

Commit 94f6b7c

Browse files
committed
Invoices no longer assign to self.data during filtering step
Instead, all invoice classes will now assign to `self.export_data` This removes ambiguity on whether the invoices will modify their internal dataframe and the need to call `copy()` on the processed dataframe
1 parent c81622d commit 94f6b7c

8 files changed

+22
-21
lines changed

process_report/invoices/NERC_total_invoice.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def output_s3_archive_key(self):
5151
return f"Invoices/{self.invoice_month}/Archive/NERC-{self.invoice_month}-Total-Invoice {util.get_iso8601_time()}.csv"
5252

5353
def _prepare_export(self):
54-
self.data = self.data[
54+
self.export_data = self.data[
5555
self.data[invoice.IS_BILLABLE_FIELD] & ~self.data[invoice.MISSING_PI_FIELD]
5656
]
57-
self.data = self.data[
58-
self.data[invoice.INSTITUTION_FIELD].isin(self.INCLUDED_INSTITUTIONS)
57+
self.export_data = self.export_data[
58+
self.export_data[invoice.INSTITUTION_FIELD].isin(self.INCLUDED_INSTITUTIONS)
5959
].copy()

process_report/invoices/billable_invoice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class BillableInvoice(invoice.Invoice):
4242
]
4343

4444
def _prepare_export(self):
45-
self.data = self.data[
45+
self.export_data = self.data[
4646
self.data[invoice.IS_BILLABLE_FIELD] & ~self.data[invoice.MISSING_PI_FIELD]
4747
]
4848
self.updated_old_pi_df = self.updated_old_pi_df.astype(

process_report/invoices/bu_internal_invoice.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ class BUInternalInvoice(invoice.Invoice):
2424
exported_columns_map = {invoice.PI_BALANCE_FIELD: "Balance"}
2525

2626
def _prepare_export(self):
27-
self.data = self.data[
27+
self.export_data = self.data[
2828
self.data[invoice.IS_BILLABLE_FIELD] & ~self.data[invoice.MISSING_PI_FIELD]
2929
]
30-
self.data = self.data[
31-
self.data[invoice.INSTITUTION_FIELD] == "Boston University"
30+
self.export_data = self.export_data[
31+
self.export_data[invoice.INSTITUTION_FIELD] == "Boston University"
3232
]
33-
self.data = self._sum_project_allocations(self.data)
33+
self.export_data = self._sum_project_allocations(self.export_data)
3434

3535
def _sum_project_allocations(self, dataframe):
3636
"""A project may have multiple allocations, and therefore multiple rows

process_report/invoices/invoice.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class Invoice:
4949
name: str
5050
invoice_month: str
5151
data: pandas.DataFrame
52+
export_data: pandas.DataFrame = None
5253

5354
def process(self):
5455
self._prepare()
@@ -93,13 +94,13 @@ def _prepare_export(self):
9394

9495
def _filter_columns(self):
9596
"""Filters and renames columns before exporting"""
96-
return self.data.copy()[self.export_columns_list].rename(
97+
self.export_data = self.export_data[self.export_columns_list].rename(
9798
columns=self.exported_columns_map
9899
)
99100

100101
def export(self):
101-
export_data = self._filter_columns()
102-
export_data.to_csv(self.output_path, index=False)
102+
self._filter_columns()
103+
self.export_data.to_csv(self.output_path, index=False)
103104

104105
def export_s3(self, s3_bucket):
105106
s3_bucket.upload_file(self.output_path, self.output_s3_key)

process_report/invoices/lenovo_invoice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class LenovoInvoice(invoice.Invoice):
1919
exported_columns_map = {invoice.SU_HOURS_FIELD: "SU Hours"}
2020

2121
def _prepare_export(self):
22-
self.data = self.data[
22+
self.export_data = self.data[
2323
self.data[invoice.SU_TYPE_FIELD].isin(self.LENOVO_SU_TYPES)
2424
]

process_report/invoices/nonbillable_invoice.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ class NonbillableInvoice(invoice.Invoice):
2424
]
2525

2626
def _prepare_export(self):
27-
self.data = self.data[~self.data[invoice.IS_BILLABLE_FIELD]]
27+
self.export_data = self.data[~self.data[invoice.IS_BILLABLE_FIELD]]

process_report/invoices/pi_specific_invoice.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class PIInvoice(invoice.Invoice):
3434
]
3535

3636
def _prepare(self):
37-
self.data = self.data[
37+
self.export_data = self.data[
3838
self.data[invoice.IS_BILLABLE_FIELD] & ~self.data[invoice.MISSING_PI_FIELD]
3939
]
40-
self.pi_list = self.data[invoice.PI_FIELD].unique()
40+
self.pi_list = self.export_data[invoice.PI_FIELD].unique()
4141

4242
def export(self):
4343
def _export_pi_invoice(pi):

process_report/process_report.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ def main():
255255
lenovo_inv = lenovo_invoice.LenovoInvoice(
256256
name=args.Lenovo_file,
257257
invoice_month=invoice_month,
258-
data=processed_data.copy(),
258+
data=processed_data,
259259
)
260260
nonbillable_inv = nonbillable_invoice.NonbillableInvoice(
261261
name=args.nonbillable_file,
262262
invoice_month=invoice_month,
263-
data=processed_data.copy(),
263+
data=processed_data,
264264
nonbillable_pis=pi,
265265
nonbillable_projects=projects,
266266
)
@@ -271,25 +271,25 @@ def main():
271271
billable_inv = billable_invoice.BillableInvoice(
272272
name=args.output_file,
273273
invoice_month=invoice_month,
274-
data=processed_data.copy(),
274+
data=processed_data,
275275
old_pi_filepath=old_pi_file,
276276
updated_old_pi_df=new_pi_credit_proc.updated_old_pi_df,
277277
)
278278

279279
nerc_total_inv = NERC_total_invoice.NERCTotalInvoice(
280280
name=args.NERC_total_invoice_file,
281281
invoice_month=invoice_month,
282-
data=processed_data.copy(),
282+
data=processed_data,
283283
)
284284

285285
bu_internal_inv = bu_internal_invoice.BUInternalInvoice(
286286
name=args.BU_invoice_file,
287287
invoice_month=invoice_month,
288-
data=processed_data.copy(),
288+
data=processed_data,
289289
)
290290

291291
pi_inv = pi_specific_invoice.PIInvoice(
292-
name=args.output_folder, invoice_month=invoice_month, data=processed_data.copy()
292+
name=args.output_folder, invoice_month=invoice_month, data=processed_data
293293
)
294294

295295
util.process_and_export_invoices(

0 commit comments

Comments
 (0)