Astropy now allows empty time object#7868
Astropy now allows empty time object#7868souravghosh97 wants to merge 1 commit intoastropy:masterfrom
Conversation
|
Check results are now reported in the status checks at the bottom of this page. |
mhvk
left a comment
There was a problem hiding this comment.
@souravghosh97 - thanks for the PR! As you'll see in the comments, I'm not sure your approach is optimal: I think it would be better to add the zerosize_ok flag to the iterator (as per #7866 (comment)).
Also, tests need to include roundtripping, i.e., conversion to output, and format/scale changes.
I made a very quick branch with my suggestion: c032e9f
Feel free to just use/copy this.
| def value(self): | ||
| raise NotImplementedError | ||
|
|
||
| def _check_val_empty(self, val): |
There was a problem hiding this comment.
I'm not sure this routine is needed (see later comment).
Also, it tests, I think, the wrong thing: an array with shape=(2, 0) is not the same as an array with empty shape (0,). I also thought we can count on val being an ndarray here.
| self.jd1 = self.jd2 = np.array([]) | ||
| return | ||
|
|
||
| iterator = np.nditer([val1, None, None, None, None, None, None], |
There was a problem hiding this comment.
I think for many cases, one doesn't have to special-case the empty shape, but one should just pass 'zerosize_ok' in the flags of nditer below (see #7866 (comment))
| isecs = ihmsfs['s'] | ||
| ifracs = ihmsfs['f'] | ||
|
|
||
| shapes = list(map(np.shape, [iys, ims, ids, ihrs, imins, isecs, ifracs])) |
There was a problem hiding this comment.
As above, the flag should suffice.
| def _check_val_type(self, val1, val2): | ||
| # Note: don't care about val2 for these classes | ||
| if val1.dtype.kind not in ('S', 'U'): | ||
| if val1.dtype.kind not in ('S', 'U', 'f'): |
There was a problem hiding this comment.
I see why you are doing this, but it is ugly! I think this does need to special-case the shape=(0,) case.
There was a problem hiding this comment.
More specifically, I think this would need to be
if val1.dtype.kind not in ('S', 'U') and val1.size > 0:
raise ...
| Time([], format='jd', scale='tai') | ||
| Time([], format='mjd', scale='tai') | ||
| Time([], format='yday', scale='tai') | ||
| Time([], format='yday', scale='utc') |
There was a problem hiding this comment.
You also need to check that output works (i.e., time.value) as well as conversions to other scales and formats. Otherwise, this will still break scripts that may have empty input.
|
Hi humans 👋 - this pull request hasn't had any new commits for approximately 8 months. I plan to close this in a month 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 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. |
|
closing in favour of #8854 |
Fixes: #7866