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

Fixed a bug in NDCubeSequence.cube_like_dimensions. #788

Merged
merged 12 commits into from
Dec 12, 2024

Conversation

PCJY
Copy link
Contributor

@PCJY PCJY commented Nov 25, 2024

PR Description

fixes issue #785

PCJY added 2 commits November 25, 2024 12:40
Did this by calling the cube_like_shape property.
@PCJY
Copy link
Contributor Author

PCJY commented Nov 25, 2024

Hi @DanRyanIrish Here is my first Pull Request, can you please review it?

@nabobalis nabobalis modified the milestones: 2.2.4, 2.2.5 Nov 26, 2024
@nabobalis nabobalis added backport 2.2 on-merge: backport to 2.2 Minor Change PR only needs one approval to merge. and removed backport 2.2 on-merge: backport to 2.2 labels Nov 26, 2024
@nabobalis nabobalis modified the milestones: 2.2.5, 2.3.0 Nov 26, 2024
@nabobalis
Copy link
Contributor

nabobalis commented Nov 26, 2024

Hello @PCJY, does this happen on a release version of ndcube or just the main version?

It might be useful to also add a unit test to check we don't break this in the future.

@DanRyanIrish
Copy link
Member

DanRyanIrish commented Nov 27, 2024

Hi @PCJY. Thanks so much for this PR. I agree with @nabobalis that we should also have a unit test for this. In addition, you should add a changelog file to describe the change that this PR makes.

For an example of a unit test, you can see here. It tests NDCubeSequence.cube_like_shape, so can be very closely adapted to this PR. Your test_cube_like_dimensions test should go in the same file, after the test_cube_like_shape test function.

For a quick explainer of changelog files, see here. You should add the file to the ndcube/changelog directory.

@DanRyanIrish DanRyanIrish self-requested a review November 27, 2024 09:25
@nabobalis
Copy link
Contributor

Does this change also need to occur to the new property as well?

@DanRyanIrish
Copy link
Member

Does this change also need to occur to the new property as well?

Which new property @nabobalis ?

@nabobalis
Copy link
Contributor

nabobalis commented Nov 28, 2024

Does this change also need to occur to the new property as well?

Which new property @nabobalis ?

warn_deprecated("Replaced by ndcube.NDCubeSequence.cube_like_shape") ? Or is the new one unitless?

@DanRyanIrish
Copy link
Member

warn_deprecated("Replaced by ndcube.NDCubeSequence.cube_like_shape") ? Or is the new one unitless?

Yes, the new one is unitless.

@DanRyanIrish
Copy link
Member

Hi @PCJY Thanks for these changes. Currently, the test is failing because of the deprecation warning that this function raises. Therefore, we have to make this test ignore such warnings. @nabobalis, do you know how to ignore deprecation warnings for a specific test?

@@ -140,7 +140,7 @@ def test_cube_like_shape(ndc, expected_shape):
],
indirect=("ndc",))
def test_cube_like_dimensions(ndc, expected_dimensions):
assert np.all(ndc.cube_like_dimensions == expected_dimensions)
assert all(assert_quantity_allclose(ndc_dim, exp_dim) for ndc_dim, exp_dim in zip(ndc.cube_like_dimensions, expected_dimensions))
Copy link
Member

Choose a reason for hiding this comment

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

To avoid the deprecation warning making this test fail, I think you should be able to use Python's catch_warnings context manager

Comment on lines 147 to 148
for ndc_dim, exp_dim in zip(ndc.cube_like_dimensions, expected_dimensions):
assert_quantity_allclose(ndc_dim, exp_dim)
Copy link
Member

Choose a reason for hiding this comment

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

This looks like a perfectly good solution. The issue before was that assert_quantity_allclose returns None if the values are the same, not true. So an alternative fix would have been

Suggested change
for ndc_dim, exp_dim in zip(ndc.cube_like_dimensions, expected_dimensions):
assert_quantity_allclose(ndc_dim, exp_dim)
assert all(assert_quantity_allclose(ndc_dim, exp_dim) is None for ndc_dim, exp_dim in zip(ndc.cube_like_dimensions, expected_dimensions))

But if this works, we can keep your solution :)

@DanRyanIrish
Copy link
Member

The pre-commit test failed. You should run tox -e codestyle locally an then commit and push the changes.

In addition, the "This branch is out-of-date with the base branch" warning below the tests means the new updates have been made to the main branch. So in addition, yout should do git pull origin main locally and then push the changes, so the PR is up-to-date.

I'll look into the docs test fail later.

@nabobalis
Copy link
Contributor

Doc failure is <unknown>:37: WARNING: py:obj reference target not found: NDCubeSequence.cube_like_dimensions [ref.obj]

@DanRyanIrish
Copy link
Member

Doc failure is <unknown>:37: WARNING: py:obj reference target not found: NDCubeSequence.cube_like_dimensions [ref.obj]

Thanks @nabobalis. Do you know what that means?

@nabobalis
Copy link
Contributor

Doc failure is <unknown>:37: WARNING: py:obj reference target not found: NDCubeSequence.cube_like_dimensions [ref.obj]

Thanks @nabobalis. Do you know what that means?

Yes I do.

changelog/788.bugfix.rst Outdated Show resolved Hide resolved
Co-authored-by: Stuart Mumford <[email protected]>
Copy link
Member

@DanRyanIrish DanRyanIrish left a comment

Choose a reason for hiding this comment

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

Congrats @PCJY on your first approved PR to ndcube!!

@DanRyanIrish DanRyanIrish merged commit b3badd6 into sunpy:main Dec 12, 2024
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Minor Change PR only needs one approval to merge.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants