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

Adding __pow__ to NDCube #678

Merged
merged 16 commits into from
Apr 23, 2024
Merged

Adding __pow__ to NDCube #678

merged 16 commits into from
Apr 23, 2024

Conversation

hayesla
Copy link
Member

@hayesla hayesla commented Apr 23, 2024

Fixes #575

This add __pow__ to NDCube

@nabobalis nabobalis added this to the 2.3.0 milestone Apr 23, 2024
@hayesla
Copy link
Member Author

hayesla commented Apr 23, 2024

why are user warnings not triggered on tests?

new_cube = ndcube_2d_ln_lt_uncert ** power
check_arithmetic_value_and_units(new_cube, cube_quantity**power)


Copy link
Member

Choose a reason for hiding this comment

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

We also need tests for when for the following cases:

  • self.uncertainty is None
  • self.unit is None

These can probably be done in the same test.

hayesla and others added 4 commits April 23, 2024 13:44
Co-authored-by: DanRyanIrish <[email protected]>
Co-authored-by: DanRyanIrish <[email protected]>
Co-authored-by: DanRyanIrish <[email protected]>
@@ -1124,6 +1124,30 @@ def test_cube_arithmetic_multiply_notimplementederror(ndcube_2d_ln_lt_units):
_ = ndcube_2d_ln_lt_units * ndcube_2d_ln_lt_units


@pytest.mark.filterwarnings('ignore::RuntimeWarning')
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be better to use np.errstate rather than this?

Copy link
Member Author

Choose a reason for hiding this comment

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

indeed

try:
new_uncertainty = new_uncertainty.propagate(np.power, self, self.data ** value, correlation=1)
except ValueError as e:
if "unsupported operation" in e.args[0]:
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 gross, we should open an issue on astropy to raise different error classes for different errors.

Copy link
Member

@Cadair Cadair left a comment

Choose a reason for hiding this comment

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

:shipit:

@DanRyanIrish DanRyanIrish merged commit 1db2816 into sunpy:main Apr 23, 2024
19 checks passed
@Cadair
Copy link
Member

Cadair commented Apr 23, 2024

shipit.mp4

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.

Support __pow__ and __rtruediv__ arithmetic operations
4 participants