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

change behaviour of gyroradius when arguments are nan #1187

Merged
merged 6 commits into from
Jul 6, 2021

Conversation

alfkoehn
Copy link
Contributor

@alfkoehn alfkoehn commented Jul 6, 2021

This PR closes #1022 . The general behaviour of gyroradius is changed such that if one of the arguments (T_i, Vperp) is nan, and the other is not supplied, no error is raised, but nan is returned.

  • I have added a changelog entry for this pull request.
  • If adding new functionality, I have added tests and
    docstrings.
  • I have fixed any newly failing tests.

@github-actions github-actions bot added the plasmapy.formulary Related to the plasmapy.formulary subpackage label Jul 6, 2021
@codecov
Copy link

codecov bot commented Jul 6, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@5f5717c). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1187   +/-   ##
=======================================
  Coverage        ?   96.98%           
=======================================
  Files           ?       71           
  Lines           ?     7022           
  Branches        ?        0           
=======================================
  Hits            ?     6810           
  Misses          ?      212           
  Partials        ?        0           

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 5f5717c...0b1e978. Read the comment docs.

@@ -1198,7 +1198,7 @@ def gyroradius(

# check 1: ensure either Vperp or T_i invalid, keeping in mind that
# the underlying values of the astropy quantity may be numpy arrays
if np.any(np.logical_not(np.logical_xor(isfinite_Vperp, isfinite_Ti))):
if np.any(np.logical_and(isfinite_Vperp, isfinite_Ti)):
Copy link
Member

Choose a reason for hiding this comment

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

Do you think we could test this to ensure it works as expected? The tests for gyroradius are located around https://github.com/PlasmaPy/PlasmaPy/blob/main/plasmapy/formulary/tests/test_parameters.py#L798 here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, didn't knew about that proper test section, sorry - had only made tests on my own. Will do the proper testing later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does testing here simply means to run test_gyroradius(), or also to modify test_gyroradius() and add some new tests? (The former one should be sufficient in my opinion but I might overlook something)

Copy link
Member

Choose a reason for hiding this comment

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

The tests are ran automatically anyway (see the Checks tab!), so that's already being done :) What I meant instead was to add (or ensure there are already! haven't checked 😅) a few checks to test_gyroradius:

  1. gyroradius(T_i = nan) == nan, no exception;
  2. gyroradius(Vperp = nan) == nan, no exception;
  3. gyroradius(T_i = nan, Vperp = nan) raises exception (there should be a pytest.raises clause around that general area we could adapt :) )

(np.isnan would be helpful for the comparison, since anything == np.nan is False, even if that anything is np.nan!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are exactly the checks I have done manually :)

Now I will try to understand the syntax in the test_gyroradius function and include them there.

Copy link
Contributor Author

@alfkoehn alfkoehn Jul 6, 2021

Choose a reason for hiding this comment

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

Note that this might not be (well, I'm pretty sure it is not) the most elegant or "pythonic" way of testing it, but all the three new cases are included via assert tests. Not sure though if this qualifies the official test criteria....?

Happy to learn how to improve the tests, if desired.

Also: thanks for your patience :)

Copy link
Member

Choose a reason for hiding this comment

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

This is literally what I'm here for :)

They're great, exactly what I was hoping for! Since the test suite isn't exploding, we can probably merge it now :)

@alfkoehn
Copy link
Contributor Author

alfkoehn commented Jul 6, 2021

@StanczakDominik I don't understand why the pre-commit.ci fails, it says

black....................................................................Failed
- hook id: black
- files were modified by this hook
reformatted plasmapy/formulary/tests/test_parameters.py

I have no idea what was actually reformatted, so I don't know what to change to let this check pass... Any hints are greatly appreciated

@StanczakDominik
Copy link
Member

Iirc the magic incantation for this is...

pre-commit.ci autofix

@alfkoehn
Copy link
Contributor Author

alfkoehn commented Jul 6, 2021

No idea about magic incantation, sorry :D

@StanczakDominik
Copy link
Member

Hah, sorry! This part is a bit new, and we need to document it better.

Copy link
Member

@StanczakDominik StanczakDominik left a comment

Choose a reason for hiding this comment

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

Looks great, let's get it in! Thanks! :)

@StanczakDominik StanczakDominik merged commit 4dae984 into PlasmaPy:main Jul 6, 2021
@alfkoehn
Copy link
Contributor Author

alfkoehn commented Jul 6, 2021

Awesome :)

@alfkoehn alfkoehn deleted the change_gyroradius_behaviour branch July 6, 2021 17:56
@qudsiramiz
Copy link
Member

Yaayyy! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plasmapy.formulary Related to the plasmapy.formulary subpackage
Projects
None yet
3 participants