Skip to content

Add support for 0d NaN / NaT Times - #10272

Closed
maxnoe wants to merge 4 commits into
astropy:mainfrom
maxnoe:time_nan
Closed

maxnoe wants to merge 4 commits into
astropy:mainfrom
maxnoe:time_nan

Conversation

@maxnoe

@maxnoe maxnoe commented May 2, 2020

Copy link
Copy Markdown
Member

Description

For further discussion relevant to #6509, I here add test cases for possible nan / NaT values for astropy.time objects.

I have also started to look into implementing this.

Comment thread astropy/time/tests/test_nan.py Resolved
@taldcroft

Copy link
Copy Markdown
Member

I haven't looked much in detail but this is a great idea to define the API with respect to Time missing values and scalars. You may want to put [skip ci] in each commit until tests are passing locally.

@mhvk

mhvk commented May 2, 2020

Copy link
Copy Markdown
Contributor

General discussion in #6509 - here just a note that if you want np.isna[nt] to work on Time, you'll need to define an __array_ufunc__ to tell how it should treat Time instances. If you'd also want things like np.nanmean to work, one would likely also need to define __array_function__ (which is planned a bit anyway, for np.linspace - see #8610.

All that said, it would be good if all these tests passed! (Except as @taldcroft noted, remove tests on private properties - those should remain implementation details - possibly including how to get isnan to work!)

@maxnoe

maxnoe commented May 2, 2020

Copy link
Copy Markdown
Member Author

@mhvk yes, thanks for the pointers.

This is what I started with, but I have not yet a working version

@maxnoe

maxnoe commented May 15, 2020

Copy link
Copy Markdown
Member Author

@mhvk I started working on this again. But defining array_ufunc is tricky. I defined it only for isnan and isnat but now stuff starts failing because what used to work, like:

np.equal(time, 0) now also calls ufunc.

Do I now have to implement every single numpy ufunc in Time.__array_ufunc. There has to be a better way.

@maxnoe
maxnoe force-pushed the time_nan branch 2 times, most recently from e068555 to de9334e Compare May 15, 2020 09:46
@mhvk

mhvk commented May 15, 2020

Copy link
Copy Markdown
Contributor

@maxnoe - indeed, every ufunc has to be dealt with. There is a mixin to let all operators go via the same path, but I'm not sure that is too helpful in this case.

That said, I actually hadn't appreciated any ufuncs worked at all on Time! Are there any tests that are actually failing?

But on reflection/inspection, I see what happens: the ufunc creates an array of Time scalars and let those subtract:

In [9]: t = Time(np.arange(50000., 50003.), format='mjd')                                                                                                                

In [10]: np.subtract(t, t)                                                                                                                                   

Out[10]: 
array([<TimeDelta object: scale='tai' format='jd' value=0.0>,
       <TimeDelta object: scale='tai' format='jd' value=0.0>,
       <TimeDelta object: scale='tai' format='jd' value=0.0>],
      dtype=object)

So, dealing with those will make things better... (right now, for 10 elements t==t is 100 times faster than np.equal(t, t)).

In any case, my sense would be to first of all think of ufuncs where we're adding new functionality, and then worry about those that we've broken.

@maxnoe maxnoe changed the title Add test cases for nan Times Add support for NaN / NaT Times Aug 20, 2020
@maxnoe maxnoe changed the title Add support for NaN / NaT Times Add support for 0d NaN / NaT Times Aug 20, 2020
@pllim

pllim commented Sep 16, 2020

Copy link
Copy Markdown
Member

Hello. I converted your PR to a draft PR due to #10706 .

@github-actions

github-actions Bot commented Sep 3, 2021

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 1 year, 14 days. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@github-actions github-actions Bot added the Close? Tell stale bot that this issue/PR is stale label Sep 3, 2021
@github-actions

github-actions Bot commented Sep 4, 2021

Copy link
Copy Markdown
Contributor

Hi humans 👋 - this pull request hasn't had any new commits for approximately 1 year, 14 days. I plan to close this in 30 days if the pull request doesn't have any new commits by then.

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add keep-open label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

If you believe I commented on this pull request incorrectly, please report this here.

@pllim

pllim commented Sep 4, 2021

Copy link
Copy Markdown
Member

Sorry for the duplicate bot posts. I fixed the bug upstream, hopefully.

@github-actions github-actions Bot added the closed-by-bot Closed by stale bot label Oct 5, 2021
@github-actions

github-actions Bot commented Oct 5, 2021

Copy link
Copy Markdown
Contributor

I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks!

If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Close? Tell stale bot that this issue/PR is stale closed-by-bot Closed by stale bot testing time

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants