Skip to content

Conversation

@davidhassell
Copy link
Collaborator

Description

Currently (v1.0.1) negative slices, i.e. slices with a negative step, such as [10:1:-1], are not allowed on chunked data. This breaks some downstream applications (e.g. cfdm and cf-python). This can be fixed.

Closes #169

Before you get started

Checklist

  • This pull request has a descriptive title and labels
  • This pull request has a minimal description (most was discussed in the issue, but a two-liner description is still desirable)
  • Unit tests have been added (if codecov test fails)
  • Any changed dependencies have been added or removed correctly (if need be)
  • If you are working on the documentation, please ensure the current build passes
  • All tests pass

@codecov
Copy link

codecov bot commented Jan 5, 2026

Codecov Report

❌ Patch coverage is 93.02326% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.33%. Comparing base (628f227) to head (54227f2).

Files with missing lines Patch % Lines
pyfive/indexing.py 93.02% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #170      +/-   ##
==========================================
+ Coverage   76.83%   77.33%   +0.49%     
==========================================
  Files          15       15              
  Lines        2936     2974      +38     
  Branches      467      477      +10     
==========================================
+ Hits         2256     2300      +44     
+ Misses        558      555       -3     
+ Partials      122      119       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@bnlawrence bnlawrence left a comment

Choose a reason for hiding this comment

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

This looks pretty straightforward I think, but I just have some minor comment comments to consider.

def __init__(self):
super().__init__("only slices with step >= 1 are supported")

# And the rest of the code is the original file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this is no longer true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's right. I think that negative step slices are OK in all cases, now ...

Copy link
Collaborator

@bnlawrence bnlawrence Jan 6, 2026

Choose a reason for hiding this comment

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

So I would remove that comment (line 50), then I think this can be approved.

elif index == Ellipsis:
raise ValueError(
"replace_negative_slices doesn't work when selection "
"contains Ellipsis. Consider running replace_ellipsis first"
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is "replace_ellipsis", would the user know about this, could it have a link?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've changed the message to

                "replace_negative_slices(selection, shape) doesn't work "
                "when selection contains Ellipsis. Consider doing "
                "selection=pyfive.indexing.replace_ellipsis(selection, shape) "
                "first"

bacfb99

# dimensions might get dropped by integer indices)
dim = 0

# Parse the indices
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it's not so much parse the indices, as "parse and replace the indices"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed: 082b00f

Copy link
Collaborator

@bnlawrence bnlawrence left a comment

Choose a reason for hiding this comment

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

I'm good to go once line 50 is gone (I would have done it myself .. .but)

@davidhassell
Copy link
Collaborator Author

I'm good to go once line 50 is gone

I'm perfectly happy to do this, but was just wondering why, as that line has "always" been there ...

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.

Allow negative slices when indexing chunked data

2 participants