Skip to content

Conversation

@JEM-Mosig
Copy link
Contributor

Resolves #109

@google-cla
Copy link

google-cla bot commented Apr 14, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Comment on lines 55 to 58
pz.select((0, 3, -2)) \
.at_instances_of(int) \
.where(lambda i: i < 0) \
.apply(lambda i: i + shift)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I should just use this instead of defining _shift_negative_indices. I'm weary of doing so because we're in the module that defines selectors here. Also, we don't need that kind of generality at this point and _shift_negative_indices avoids some overhead

Copy link
Collaborator

Choose a reason for hiding this comment

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

Defining a new function here like you've done makes sense to me, the logic is probably too simple to benefit much from using selectors. (You could also just inline the logic into the call site since it's only used once.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You could also just inline the logic into the call site since it's only used once

I'd prefer to keep it separate so code blocks stay short and hence easy to interpret

@JEM-Mosig JEM-Mosig marked this pull request as ready for review April 15, 2025 09:56
Copy link
Collaborator

@danieldjohnson danieldjohnson left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

It looks like one of our CI steps is currently failing (uv run pyink penzai tests --check). Mind fixing this? If you run uv run pyink penzai tests it should reformat everything automatically.

(See here for the full set of checks that gets run in CI.)

Comment on lines 29 to 47
import pytest


@pytest.mark.parametrize(
"input_indices, shift, expected_output",
[
((), 1, ()),
([0, 3, -2], len(range(6)), (0, 3, 4)),
]
)
def test_shift_negative_indices(
input_indices: Iterable[int],
shift: int,
expected_output: tuple[int, ...],
):
assert (
penzai.core.selectors._shift_negative_indices(input_indices, shift=shift)
== expected_output
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would you mind adding this as an absltest-style test (as a method inside SelectorsTest) instead of using pytest here? The rest of the tests do not use pytest yet and I'd prefer to be consistent here for now.

Comment on lines 55 to 58
pz.select((0, 3, -2)) \
.at_instances_of(int) \
.where(lambda i: i < 0) \
.apply(lambda i: i + shift)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Defining a new function here like you've done makes sense to me, the logic is probably too simple to benefit much from using selectors. (You could also just inline the logic into the call site since it's only used once.)

@JEM-Mosig
Copy link
Contributor Author

Thanks for the review! I'll address the comments some time this week.

@JEM-Mosig
Copy link
Contributor Author

@danieldjohnson I've addressed your comments. All tests pass locally. Could you have another look?

Copy link
Collaborator

@danieldjohnson danieldjohnson left a comment

Choose a reason for hiding this comment

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

Thanks much!

@danieldjohnson danieldjohnson merged commit 5533d86 into google-deepmind:main Apr 26, 2025
2 checks passed
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.

pick_nth_selected(-1) should select the last node

2 participants