Skip to content

Implement take and take_along_axis for time dtypes#205

Merged
Christian Bourjau (cbourjau) merged 2 commits into
mainfrom
impl-take-and-take_along_axis-for-time
Apr 7, 2026
Merged

Implement take and take_along_axis for time dtypes#205
Christian Bourjau (cbourjau) merged 2 commits into
mainfrom
impl-take-and-take_along_axis-for-time

Conversation

@cbourjau
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Contributor

@SamuelLessmannQC SamuelLessmannQC left a comment

Choose a reason for hiding this comment

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

Is there a specific reason not to reshape like for repeat as done here?

This fails:

@pytest.mark.parametrize("dtype", ["datetime64[s]", "timedelta64[s]"])
def test_take_axis_none_flattens(dtype):
    np_arr = np.asarray(
        [
            [1, "NaT", 0],
            [10, 20, 30],
        ],
        dtype=dtype,
    )

    def do(npx):
        indices = np.asarray([4, 1, -1], dtype=np.int64)
        return npx.take(npx.asarray(np_arr), npx.asarray(indices))

    np.testing.assert_array_equal(do(ndx).unwrap_numpy(), do(np))

@cbourjau Christian Bourjau (cbourjau) force-pushed the impl-take-and-take_along_axis-for-time branch from 956a6c6 to b1fa026 Compare April 7, 2026 11:58
@cbourjau
Copy link
Copy Markdown
Collaborator Author

take[_along_axis] and repeat have quite different semantics with regard to their axis argument in the array-api. Some of the test cases, as well as your example, are not specified by the array-api. This was a good catch, though! We didn't validate the arguments properly and had diverging behavior compared to NumPy. I added proper validation and updated the test cases.

@cbourjau Christian Bourjau (cbourjau) merged commit bfed1db into main Apr 7, 2026
46 checks passed
@cbourjau Christian Bourjau (cbourjau) deleted the impl-take-and-take_along_axis-for-time branch April 7, 2026 12:40
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