Skip to content

Made error message more helpful when cropping to a single pixel #869

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

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/869.doc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clarified an error message that cropping to single pixel is not supported only when ``keepdims=False`` (the default value).
2 changes: 1 addition & 1 deletion docs/explaining_ndcube/slicing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ But if :code:`keepdims=True`, a valid NDCube is returned with N length-1 dimensi
>>> my_cube_roi = my_cube.crop(lower_left, upper_right, lower_right, upper_left)
Traceback (most recent call last):
...
ValueError: Input points causes cube to be cropped to a single pixel. This is not supported.
ValueError: Input points causes cube to be cropped to a single pixel. This is not supported when keepdims=False.
>>> my_cube_roi_keep = my_cube.crop(lower_left, upper_right, lower_right, upper_left,
... keepdims=True)
>>> my_cube_roi_keep.shape
Expand Down
4 changes: 2 additions & 2 deletions ndcube/utils/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
Denotes whether cropping is done using high-level objects or "values",
i.e. low-level objects.
keep_dims : `bool`
keepdims : `bool`
Copy link
Member

Choose a reason for hiding this comment

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

why is keepdims, not keep_dims?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm simply making the docstring match the API.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this was more of a question for the two maintainers of ndcube than you.

@Cadair and @DanRyanIrish, explain yourselves.

If `False`, returned item will drop length-1 dimensions otherwise, item will keep length-1 dimensions.
Returns
Expand Down Expand Up @@ -208,7 +208,7 @@ def get_crop_item_from_points(points, wcs, crop_by_values, keepdims):
# If item will result in a scalar cube, raise an error as this is not currently supported.
if result_is_scalar:
raise ValueError("Input points causes cube to be cropped to a single pixel. "
"This is not supported.")
"This is not supported when keepdims=False.")
return tuple(item)


Expand Down