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

Refactor utility functions #55

Merged
merged 15 commits into from
May 18, 2021
Merged

Conversation

gwaybio
Copy link
Member

@gwaybio gwaybio commented May 11, 2021

The utility functions were getting clunky. I went to add new functionality to grit, but I struggled to figure out exactly where I should be adding it. This led me to this refactoring exercise.

No functionality was changed in this pull request. Only names and locations of python utility functions and tests. I also needed to modify several additional functions to fix import statements.

I also made super minor changes to formatting and fixed a deprecated testing warning (reverted back, see #56 ).


Note, I did fix a separate deprecation warning for numpy built-in types (see https://numpy.org/doc/stable/release/1.20.0-notes.html#deprecations)

@gwaybio
Copy link
Member Author

gwaybio commented May 11, 2021

cc @michaelbornholdt - I just gave you triage access to the repo, so that you are able to more effectively review this PR. Once you accept the invite, I will add you as a reviewer. Thanks! :)

@codecov-commenter
Copy link

codecov-commenter commented May 12, 2021

Codecov Report

Merging #55 (03c09ee) into master (7f94b11) will increase coverage by 0.06%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #55      +/-   ##
==========================================
+ Coverage   98.38%   98.45%   +0.06%     
==========================================
  Files          24       30       +6     
  Lines         867      905      +38     
==========================================
+ Hits          853      891      +38     
  Misses         14       14              
Flag Coverage Δ
unittests 98.45% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...iner_eval/tests/test_operations/test_enrichment.py 100.00% <ø> (ø)
cytominer_eval/evaluate.py 100.00% <100.00%> (ø)
cytominer_eval/operations/enrichment.py 100.00% <100.00%> (ø)
cytominer_eval/operations/grit.py 100.00% <100.00%> (ø)
cytominer_eval/operations/mp_value.py 100.00% <100.00%> (ø)
cytominer_eval/operations/precision_recall.py 100.00% <100.00%> (ø)
...miner_eval/operations/replicate_reproducibility.py 100.00% <100.00%> (ø)
cytominer_eval/tests/test_evaluate.py 100.00% <100.00%> (ø)
cytominer_eval/tests/test_operations/test_grit.py 100.00% <100.00%> (ø)
...ominer_eval/tests/test_operations/test_mp_value.py 100.00% <100.00%> (ø)
... and 19 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f94b11...03c09ee. Read the comment docs.

@gwaybio
Copy link
Member Author

gwaybio commented May 12, 2021

alright @michaelbornholdt - this is ready for your eyes.

This blog post might be helpful to determine how to review.

Personally, I find reviewing other PRs to be helpful for the times when it's me actually proposing the changes. For this reason (and for an independent reason: I think more eyes on code the better) I am requesting your review. Do you think you'll be able to do this in a timely fashion? Hopefully by tomorrow?

FWIW, I think this PR is an easy one to start with. I'm not changing any functionality, just structure.

Copy link
Collaborator

@michaelbornholdt michaelbornholdt left a comment

Choose a reason for hiding this comment

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

Overall very clear PR @gwaygenomics . I only have mini suggestions and questions.
I will run Black over all the code because I remember it having some issues and we can use this refactoring to solve those.

@@ -8,7 +8,7 @@
from typing import List, Union

from cytominer_eval.transform import metric_melt
from cytominer_eval.transform.util import check_replicate_groups
from cytominer_eval.utils.transform_utils import check_replicate_groups
Copy link
Collaborator

Choose a reason for hiding this comment

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

For me, this line gives an error because utils are not imported here or in the init.py file. But I am unsure why the tests don't give that error?

This applies to all imports of util below

Copy link
Member Author

Choose a reason for hiding this comment

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

oh interesting, what is the error?

Is it possible that your testing environment is out-of-date?

I also added a __init__.py file inside cytominer_eval/utils - so this might help. It should have been there in the first place, so thanks for making this note.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea I know it works, for some reason pycharm is complaining about it. I think it's because if you run that file on its own, it won't find the util.
but all good

@@ -202,7 +208,9 @@ def test_evaluate_grit():
top_result = (
grit_results_df.sort_values(by="grit", ascending=False)
.reset_index(drop=True)
.iloc[0,]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this black?
it doesn't seem like a helpful change in code to me. Same goes for the lines below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it is, just checked it. I do not know why black is only modifying this now...

It is definitely a non-functional change, but it's also harmless. I think we can ignore it

get_grit_entry,
calculate_grit,
)


Copy link
Collaborator

Choose a reason for hiding this comment

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

This is something we need to change for some other files, I will point out below where we are getting the two spacing incorrect. This line is correct, but other files are not

Copy link
Member Author

Choose a reason for hiding this comment

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

nice! Weird that black didn't catch the other one. I wonder if it's a version thing.

These version differences could get annoying... I wondered if there is a way to automate black, and it looks like there is via github actions! https://github.com/psf/black/actions/runs/17913292/workflow

I added #57 for us to track it there.

Thanks for adding the extra changes


from cytominer_eval.utils.availability_utils import get_available_grit_summary_methods

random.seed(123)
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be really honest Greg, I think you should definitely change this to be seed(42) for everything 🤷 :)

Copy link
Member Author

Choose a reason for hiding this comment

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

hahaha, yes, it is the answer to the universe after all. Feel free to fix in your next PR :)

cytominer_eval/utils/grit_utils.py Outdated Show resolved Hide resolved
cytominer_eval/utils/grit_utils.py Outdated Show resolved Hide resolved
cytominer_eval/utils/transform_utils.py Outdated Show resolved Hide resolved
@michaelbornholdt
Copy link
Collaborator

And Black checks out with no errors! NICE

gwaybio and others added 4 commits May 18, 2021 13:48
Fixing spaces after function import, docstring consistency, and a missing numpy builtin update

Co-authored-by: Michael Bornholdt <[email protected]>
Copy link
Member Author

@gwaybio gwaybio left a comment

Choose a reason for hiding this comment

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

Thanks for these comments. I've either made replies that require your followup or resolved the issue. I'll re-request your review.

The most important comment is for you to confirm that these updates work on your end. Although that is less important since they do seem to pass tests. Weird!

@@ -202,7 +208,9 @@ def test_evaluate_grit():
top_result = (
grit_results_df.sort_values(by="grit", ascending=False)
.reset_index(drop=True)
.iloc[0,]
Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it is, just checked it. I do not know why black is only modifying this now...

It is definitely a non-functional change, but it's also harmless. I think we can ignore it

get_grit_entry,
calculate_grit,
)


Copy link
Member Author

Choose a reason for hiding this comment

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

nice! Weird that black didn't catch the other one. I wonder if it's a version thing.

These version differences could get annoying... I wondered if there is a way to automate black, and it looks like there is via github actions! https://github.com/psf/black/actions/runs/17913292/workflow

I added #57 for us to track it there.

Thanks for adding the extra changes

cytominer_eval/utils/transform_utils.py Outdated Show resolved Hide resolved

from cytominer_eval.utils.availability_utils import get_available_grit_summary_methods

random.seed(123)
Copy link
Member Author

Choose a reason for hiding this comment

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

hahaha, yes, it is the answer to the universe after all. Feel free to fix in your next PR :)

@gwaybio gwaybio requested a review from michaelbornholdt May 18, 2021 17:55
Copy link
Collaborator

@michaelbornholdt michaelbornholdt left a comment

Choose a reason for hiding this comment

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

I'm fine with all of this.
Yes, should definitely set the exact config and version for black.
Ideally, you would also want to use pipenv instead of requirements.txt

You can merge yourself :)

@michaelbornholdt
Copy link
Collaborator

@gwaygenomics

@gwaybio
Copy link
Member Author

gwaybio commented May 18, 2021

Awesome, I will merge now. Thanks!

Ideally, you would also want to use pipenv instead of requirements.txt

I am interested. Can you elaborate? Perhaps you can elaborate in a new github issue so we can possibly implement this enhancement in the future?

@gwaybio gwaybio merged commit 9569721 into cytomining:master May 18, 2021
@gwaybio gwaybio deleted the refactor-utils branch May 18, 2021 18:13
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.

3 participants