Skip to content

Conversation

@mhvk
Copy link
Contributor

@mhvk mhvk commented Jun 17, 2020

In #10337, an __array_function__ override was introduced, which allows some numpy functions to behave as expected on SkyCoord and Time. It was a strict whitelist, however, which breaks numpy functions that sort-of worked already (sort-of, since often an object array was returned).

This PR returns to the old behaviour by passing on arguments to bare numpy function if it is not among the known functions.

fixes #10501

@taldcroft - I must admit I had no idea that np.diff(time) and np.sum(timedelta) even worked (if very slowly). Obviously, the final goal should be to support those properly, but this PR is just to fix the regression caused by #10337.

mhvk added 2 commits June 17, 2020 13:29
This means that, e.g., `np.diff(time)` will continue to return an object
array with `TimeDelta` instances.
@mhvk mhvk added time Bug Affects-dev PRs and issues that do not impact an existing Astropy release labels Jun 17, 2020
@mhvk mhvk added this to the v4.2 milestone Jun 17, 2020
@mhvk mhvk requested a review from taldcroft June 17, 2020 17:37
@astropy-bot astropy-bot bot added the utils label Jun 17, 2020
@mhvk mhvk removed the Affects-dev PRs and issues that do not impact an existing Astropy release label Jun 17, 2020
Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

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

@mhvk - this looks good, thanks! The original PASSTHROUGH_FUNCTIONS never gave me a good feeling, and now I know why. 😄

@mhvk
Copy link
Contributor Author

mhvk commented Jun 18, 2020

Thanks. It probably was a mistake, though it is also not good to rely on a private numpy implementation detail... The problem with __array_function__ is that it is all or nothing. But seeing that things like np.sum are actually used in the wild, it will be good to have implementations for them that do not rely on casting to an object array of Time scalars!

@mhvk mhvk merged commit 427ff26 into astropy:master Jun 18, 2020
@mhvk mhvk deleted the time-delta-sum-diff-regression branch June 18, 2020 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TimeDelta does not support np.sum anymore

2 participants