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

Refactored BU Internal Invoice #71

Merged
merged 2 commits into from
Sep 6, 2024

Conversation

QuanMPhm
Copy link
Contributor

Closes #67. A new bu_internal_invoice.py file has been added. Note that the BU Internal invoice depends on the billable invoice. The test case for the BU Internal invoice has been modified appropriately.

@QuanMPhm QuanMPhm requested review from knikolla and naved001 July 15, 2024 18:24
@QuanMPhm QuanMPhm force-pushed the 52.4/refactor_bu_internal branch from 758bb8c to 14df6c0 Compare July 17, 2024 17:19
@QuanMPhm
Copy link
Contributor Author

@knikolla This may be too much but...since I'll be doing more nuanced refactoring with the BU Internal invoice, should that be a separate commit as well? Some of the "nuanced refactoring" has already been added to the first commit, so I wonder if its still worth the effort to split to commit and reorganize things.

@knikolla
Copy link
Contributor

@knikolla This may be too much but...since I'll be doing more nuanced refactoring with the BU Internal invoice, should that be a separate commit as well? Some of the "nuanced refactoring" has already been added to the first commit, so I wonder if its still worth the effort to split to commit and reorganize things.

Think of it this way. Your goal is to make reviewing a PR as easy as possible. Splitting things into different commits often enables that by grouping a set of changes together with a clear commit message and description. This allows one commit to do one thing and do it well and clearly.

To understand what making a PR easier to review means, you should go through the process of reviewing your own PRs (and obviously the code of others). Some questions to think about.

  • Is it clear what the PR is trying to accomplish (and each commit)? (clear scope?)
  • Is it hard to know where to even start reviewing this PR/commit? How could you make it easier for a reviewer to know where to start? (too big?)
  • Once you start reviewing, how do you progress? Do you go top to bottom? Do you find yourself scrolling up and down? Which parts do you find yourself coming back to the most?
  • Are there particular parts that are really hard for you to understand? How could you make those parts easier to review and understand?

Sometimes just splitting things into several commits significantly helps. Sometimes it doesn't. I think in this case it will.

But ultimately, there is no single best answer on how to organize changes and you shouldn't seek to find an answer that fits every solution. Perfect is the enemy of done, and engineering software is a game of trade offs. You're trying to optimize both your time, the time of reviewers, your cognitive workload, and the cognitive workload of reviewers.

@QuanMPhm QuanMPhm force-pushed the 52.4/refactor_bu_internal branch from 14df6c0 to 1fcb400 Compare July 30, 2024 15:09
@QuanMPhm
Copy link
Contributor Author

@knikolla I have re-organized the commits. Now, the first commit will only show code copying and the initial implementation of the BU-Internal invoice. The second one contains more detailed refactoring decisions.

@QuanMPhm QuanMPhm requested a review from knikolla July 30, 2024 15:11
Copy link
Collaborator

@naved001 naved001 left a comment

Choose a reason for hiding this comment

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

will continue to review this. Thanks for all the docstrings!

bu_internal_inv = bu_internal_invoice.BUInternalInvoice(
name=args.BU_invoice_file,
invoice_month=invoice_month,
data=billable_inv.data,
Copy link
Collaborator

Choose a reason for hiding this comment

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

will this modify the billable_inv dataframe? The reason I ask this is because we could consolidate all the s3 exports later. something like:

if args.upload_to_s3:
    bucket = get_invoice_bucket()
    billable_inv.export_s3(bucket)
    bu_internal_inv.export_s3(bucket)

Copy link
Collaborator

Choose a reason for hiding this comment

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

also, it's just good to understand if this does modify it because then it would mean that after this runs "billable_inv" is no longer what it says (it may have turned into bu_internal_inv)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I don't explicitly call copy() on a dataframe, then you can assume that the same dataframe is being assigned by reference:

a = pd.DataFrame({'a': [1,2,3,4],
                  'b': [1,2,3,4]})
b = a
b.loc[0, 'a'] = 100
print(a)
print(b)>>> 
>>> a = pd.DataFrame({'a': [1,2,3,4],
...                   'b': [1,2,3,4]})
>>> b = a
>>> b.loc[0, 'a'] = 100
>>> print(a)
     a  b
0  100  1
1    2  2
2    3  3
3    4  4
>>> print(b)
     a  b
0  100  1
1    2  2
2    3  3
3    4  4 

I will make sure each invoice's dataframes won't reference each other when exported together like in your suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@naved001 I'll consolidate all the export() and export_s3() calls together after your detailed review.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@QuanMPhm thanks, this largely looks fine to me.

Copy link
Contributor Author

@QuanMPhm QuanMPhm Aug 22, 2024

Choose a reason for hiding this comment

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

While consolidating the export statements, I thought that it would make the code more organized if I process and export the invoices in the same code block. So instead of consolidating all the export() calls together, I defined process_and_export_invoices to process and export a list of invoices.

For now, process_and_export_invoices is called twice. First to export the nonbillable, billable, and lenovo invoice. Second to export the HU-BU and BU-Internal, since these two invoices depend on processing that's done in the billable invoice.

@naved001 What do you think about this?

@QuanMPhm QuanMPhm force-pushed the 52.4/refactor_bu_internal branch 2 times, most recently from 3027633 to a3eccfa Compare August 22, 2024 15:49
Copy link
Contributor

@knikolla knikolla left a comment

Choose a reason for hiding this comment

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

Looks almost there!

@QuanMPhm QuanMPhm force-pushed the 52.4/refactor_bu_internal branch from a3eccfa to b024d59 Compare August 26, 2024 19:25
@knikolla
Copy link
Contributor

knikolla commented Sep 5, 2024

@QuanMPhm can you fix the merge conflicts?

@naved001 would appreciate if you can you try to give this a review this week.

code into `bu_internal_invoice.py`

This is the prerequisite step before more detailed refactoring
of the BU-Internal invoice
…oice

The BU-Internal and billable invoice now subclasses from `discount_invoice`,
an invoice class which implements a function to apply a flat discount
on a PI's projects. This reduces some code redundancy since the
New-PI credit and the BU subsidy share some similar logic.

Additional smaller changes is done to improve code readability.
@QuanMPhm QuanMPhm force-pushed the 52.4/refactor_bu_internal branch from b024d59 to eb2d471 Compare September 5, 2024 20:54
@QuanMPhm
Copy link
Contributor Author

QuanMPhm commented Sep 5, 2024

@naved001 I have rebased the PR.

@QuanMPhm QuanMPhm merged commit 19ca40b into CCI-MOC:main Sep 6, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor BU Internal invoice
4 participants