OpenRefine / OpenRefine/OpenRefine

Improve array indexing consistency

Open
#5,690 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

grel Type: Bug Type: Feature Request
Dominant language
Java
Stars
12k
Forks
2.2k
Avg merge
1d 14h
Merged PRs (30d)
27

Description

This is an extension of #5361.

In grel, if I have an array a which is ["x","y"], say, then I can index a with values -2, -1 ,0 , and 1 with no error and the logic, for the negative values, has a well-defined (and documented) meaning in terms of referencing from the end of the array (i.e. a[-1] is "y" in this instance). And if I go out of bounds with a positive index, such as a[2], then this results in an out-of-bounds error. However, if I go out of bounds with a negative index, such as a[-3], then this just returns the first element of a and never gives an error. I suggest it should give an error.

The use of a second indexing argument to describe a range (e.g. a[0,2]) is also inconsistent, as described in #5361. If we call that second argument M, then in general the last element of the range is the (M-1)th, where negative values of M reference the array from the end as per the first argument (e.g. a[-2,-1] would give "x" in the example array above). However M=0 is an exception since it does not result in the last element of the range being the -1th (i.e. the first from the end) - instead you always get an empty array when M=0 (so a[-2,0] gives [] instead of ["x","y"] which I think would be more consistent). Moreover, there is no out-of bounds condition with the second argument. If M > length(a) then it behaves like length(a) (e.g. a[1,5] gives the same result as a[1,2]), and if M is less than -length(a) then it behaves like -length(a) (which always results in an empty range). Would it not be more consistent to produce bounding errors with the second argument as for the first?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests. Start by locating the GREL array-indexing implementation and existing tests for negative and range indices, then compare their behavior with the examples given. Done means the agreed indexing rules consistently report out-of-bounds errors and have regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.