Skip to content

Astropy now allows empty time object#7868

Closed
souravghosh97 wants to merge 1 commit intoastropy:masterfrom
souravghosh97:EmptyTimeObject
Closed

Astropy now allows empty time object#7868
souravghosh97 wants to merge 1 commit intoastropy:masterfrom
souravghosh97:EmptyTimeObject

Conversation

@souravghosh97
Copy link
Copy Markdown

>>> from astropy.time import Time
>>> Time([], format='jd')
<Time object: scale='utc' format='jd' value=[]>

Fixes: #7866

@astropy-bot
Copy link
Copy Markdown

astropy-bot bot commented Oct 7, 2018

Check results are now reported in the status checks at the bottom of this page.

Copy link
Copy Markdown
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

@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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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]))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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'):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see why you are doing this, but it is ugly! I think this does need to special-case the shape=(0,) case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@pllim pllim added this to the v2.0.10 milestone Oct 17, 2018
@bsipocz bsipocz modified the milestones: v2.0.10, v2.0.11 Nov 13, 2018
@bsipocz bsipocz modified the milestones: v2.0.11, v2.0.12 Dec 31, 2018
@pllim pllim modified the milestones: v2.0.12, v2.0.13 Feb 20, 2019
@bsipocz bsipocz modified the milestones: v2.0.13, v2.0.14 Jun 7, 2019
@bsipocz bsipocz modified the milestones: v2.0.14, v2.0.15 Jun 15, 2019
@astropy-bot
Copy link
Copy Markdown

astropy-bot bot commented Jun 15, 2019

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 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.

@mhvk
Copy link
Copy Markdown
Contributor

mhvk commented Jun 15, 2019

closing in favour of #8854

@mhvk mhvk closed this Jun 15, 2019
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.

Allow empty Time objects

4 participants