Skip to content

Commit

Permalink
Merge pull request #9624 from taldcroft/time-fix-mask-init
Browse files Browse the repository at this point in the history
Fix bug when Time object is created with only masked elements
  • Loading branch information
bsipocz committed Nov 19, 2019
2 parents c0e2cf7 + 036e905 commit 24b0f59
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -1097,6 +1097,8 @@ astropy.tests
astropy.time
^^^^^^^^^^^^

- Fix bug when ``Time`` object is created with only masked elements. [#9624]

astropy.timeseries
^^^^^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions astropy/time/core.py
Expand Up @@ -489,6 +489,7 @@ def _init_from_vals(self, val, val2, format, scale, copy,
# with shape broadcastable to jd2.
if mask is not False:
mask = np.broadcast_to(mask, self._time.jd2.shape)
self._time.jd1[mask] = 2451544.5 # Set to JD for 2000-01-01
self._time.jd2[mask] = np.nan

def _get_time_fmt(self, val, val2, format, scale,
Expand Down
9 changes: 9 additions & 0 deletions astropy/time/tests/test_mask.py
Expand Up @@ -149,6 +149,15 @@ def test_masked_input():
assert t2.masked is True


def test_all_masked_input():
"""Fix for #9612"""
# Test with jd=0 and jd=np.nan. Both triggered an exception prior to #9624
# due to astropy.utils.exceptions.ErfaError.
for val in (0, np.nan):
t = Time(np.ma.masked_array([val], mask=[True]), format='jd')
assert str(t.iso) == '[--]'


def test_serialize_fits_masked(tmpdir):
tm = Time([1, 2, 3], format='cxcsec')
tm[1] = np.ma.masked
Expand Down

0 comments on commit 24b0f59

Please sign in to comment.