-
Notifications
You must be signed in to change notification settings - Fork 38
Modernize NumPy Random Functions and Fix Mypy Errors for #756 - Shadow PR #771
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
base: master
Are you sure you want to change the base?
Conversation
generator (rng) instead of legacy np.random or Python's random module and unpins the NumPy version in pyproject.toml
…-laarej/malariagen-data-python into GH756-mohamed-laarej-shadow
Hi @jonbrenas, thanks for creating this PR and incorporating my recent random generation updates! Regarding your comment about "troubles with int casting," I believe the test failures are due to Happy to help apply these |
Thanks @mohamed-laarej. It would be great if you could address these errors but the idea, at least for now, is that you would make the change in your own PR and I would shadow them here (you can ping me when you think your changes are ready and I'll do the shadowing then). It is a very cumbersome process that should be made simpler once you are added to the team. |
Hi @jonbrenas , Thanks for the clarification on the workflow and for your feedback on the int casting issues! I also wanted to share my thanks to @ahernank for the recent team invitation I appreciate it. Understood that for these current changes, the plan is for me to address the I'll be sure to ping you on PR #760 once it's updated. Please let me know if you'd still prefer to shadow the changes, or if I should proceed more directly now that I have team access. Thanks! |
Thanks @mohamed-laarej. As I said in the email I just sent you, @ahernank added you to this repo so you should be able to push to this PR from now on if you so choose. I think it would be a good idea, for consistency's sake more than correctness of code, if all our |
Hi @jonbrenas, Thanks for the update and for confirming I can push directly to this PR branch! That will definitely make things easier. I understand the request for consistency with the random calls. I will do a thorough scan of the tests and update all remaining instances of Python's I'll also ensure the I'll push the changes to this branch once I've completed the updates and tested them locally. I'll let you know when it's ready for another look. |
- Replaced all Python random.choice() with rng.choice() for consistency - Replaced random.sample() with rng.choice(..., replace=False) - Added .tolist() to convert NumPy arrays to Python lists where needed - Added str() casting for np.str_ values to ensure Python string compatibility - Fixed 'low >= high' errors in rng.integers() calls by ensuring high > low - Specifically fixed tests/anoph/test_frq.py by changing rng.integers(1, len(cohorts_areas)) to rng.integers(1, len(cohorts_areas)+1) to avoid invalid ranges - Applied int() casting to NumPy integer types where Python int was expected - Fixed site_mask selection to ensure only valid masks are used for each test context Addresses feedback from PR #760 and resolves test failures.
Hi @jonbrenas, While fixing the test failures, I ran into a remaining issue in I'm considering two options to address this: Add a Lower the Would you prefer one of these approaches, or suggest a better alternative? |
Hi @mohamed-laarej, I think lowering |
… fix CI notebook execution
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #771 +/- ##
==========================================
- Coverage 96.13% 96.11% -0.02%
==========================================
Files 47 47
Lines 4683 4687 +4
==========================================
+ Hits 4502 4505 +3
- Misses 181 182 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Trying to solve the notebook issue
Solving the linting issue
Rolling back changes
Thanks @mohamed-laarej. The issue with the notebooks was an errant ','. Feel free to change the status of this PR if you think it is ready to be reviewed. |
Hi @jonbrenas, |
Thanks @mohamed-laarej. Sorry, it has been a while, I hadn't seen your message. If I remember correctly, the extra |
sample_sets = random.choice(all_sample_sets) | ||
site_mask = random.choice(api.site_mask_ids + (None,)) | ||
sample_sets = rng.choice(all_sample_sets) | ||
if isinstance(fixture, Af1Simulator): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remind me why it needs to be more complex than what it used to be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jonbrenas ,
I believe that part was added due to a mypy
issue or possibly a test failure related to site_mask
values when using ["gamb_colu_arab
", "gamb_colu
", "arab
"] across all fixture types. I don't recall the exact error message, but I think mypy
(or the tests) was unhappy when some simulators were paired with incompatible or undefined site masks. That’s why I added the isinstance
check to restrict values to valid options per simulator.
Happy to revisit this and simplify it if needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mohamed-laarej. At some point, we might have different site_mask
s so it would be better if didn't have that hard-coded.
260a0d3
to
3feb26e
Compare
Hi @jonbrenas , I have now force-pushed to remove those commits from this PR. You should see that the commits ee3f144 and 260a0d3 are no longer present here. My apologies again for the mix-up. I'm now proceeding with pushing the correct changes to the right branch for PR #755. Thanks for your understanding! |
Looks like this PR has unresolved conflicts and test failures. |
It looks like it needs more clean-up after the erroneous push. It doesn't look too bad. @mohamed-laarej, do you think you can do it? |
Yes @jonbrenas , I can take care of the clean-up. |
Addresses #756.
Shadows #760.
Thanks @mohamed-laarej. I think there are some troubles with
int
casting, though.