Skip to content

Conversation

@timsaucer
Copy link
Member

@timsaucer timsaucer commented Aug 28, 2025

Which issue does this PR close?

This is a user request but no issue was opened.

Rationale for this change

With this you can do slicing of arrays via expression. For example, suppose you have this data frame:

+----------------------+
| a                    |
+----------------------+
| [1.0, 2.0, 3.0, 3.0] |
| [4.0, 5.0, 3.0]      |
| [6.0]                |
+----------------------+

You could do df.with_column("a[1:3]", column("a")[1:3]) to get

+----------------------+------------+
| a                    | a[1:3]     |
+----------------------+------------+
| [1.0, 2.0, 3.0, 3.0] | [2.0, 3.0] |
| [4.0, 5.0, 3.0]      | [5.0, 3.0] |
| [6.0]                | []         |
+----------------------+------------+

What changes are included in this PR?

Updates __getitem__ to take slice.
Adds unit tests.

Are there any user-facing changes?

No

TODO

  • Add to the online documentation
  • Update function docstring

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @timsaucer -- I have a suggestion about testing, but otherwise looks good to me

),
(
lambda col: col[literal(1) : literal(4) : literal(2)],
lambda data: [arr[1:4:2] for arr in data],
Copy link
Contributor

Choose a reason for hiding this comment

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

should we also test non literal expressions? Even if they are supposed to error?

Copy link
Member Author

Choose a reason for hiding this comment

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

They will not error. Unit test added to demonstrate.

@timsaucer timsaucer merged commit c609dfa into apache:main Sep 5, 2025
16 checks passed
@timsaucer timsaucer deleted the feat/array-slice-via-getitem branch September 5, 2025 17:14
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.

2 participants