diff --git a/CHANGES.rst b/CHANGES.rst
index 0dca0f92a..a98181f2b 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,3 +1,13 @@
+1.5.2 (unreleased)
+==================
+
+Bug Fixes
+---------
+
+- Avoid Astropy Time error for SIAResult.dateobs when
+ VOX:Image_MJDateObs or ssa:DataID.Date is nan. [#550]
+
+
1.5.1 (2024-02-21)
==================
diff --git a/pyvo/dal/sia.py b/pyvo/dal/sia.py
index d2efcc1ee..2d72453cc 100644
--- a/pyvo/dal/sia.py
+++ b/pyvo/dal/sia.py
@@ -35,6 +35,7 @@
from astropy.coordinates import SkyCoord
from astropy.time import Time
from astropy.units import Quantity, Unit
+import numpy as np
from .query import DALResults, DALQuery, DALService, Record
from .mimetype import mime2extension
@@ -702,10 +703,13 @@ def dateobs(self):
as an astropy.time.Time instance
"""
dateobs = self.getbyucd("VOX:Image_MJDateObs")
- if dateobs:
- return Time(dateobs, format="mjd")
- else:
- return None
+ try:
+ if not dateobs or np.isnan(dateobs):
+ return None
+ except TypeError:
+ # np.isnan can only check floats. If can't check for nan, pass it along
+ pass
+ return Time(dateobs, format="mjd")
@property
def naxes(self):
diff --git a/pyvo/dal/ssa.py b/pyvo/dal/ssa.py
index ea577e897..021b6df2b 100644
--- a/pyvo/dal/ssa.py
+++ b/pyvo/dal/ssa.py
@@ -39,6 +39,7 @@
from astropy.units import spectral as spectral_equivalencies
from astropy.io.votable.tree import Field
from astropy.table import Table
+import numpy as np
from .query import DALResults, DALQuery, DALService, Record
from .mimetype import mime2extension
@@ -698,10 +699,13 @@ def dateobs(self):
observational data that went into the spectrum
"""
dateobs = self.getbyutype("ssa:DataID.Date", decode=True)
- if dateobs:
- return Time(dateobs, format="iso")
- else:
- return None
+ try:
+ if not dateobs or np.isnan(dateobs):
+ return None
+ except TypeError:
+ # np.isnan can only check floats. If can't check for nan, pass it along
+ pass
+ return Time(dateobs, format="iso")
@property
def instr(self):
diff --git a/pyvo/dal/tests/data/sia/dataset.xml b/pyvo/dal/tests/data/sia/dataset.xml
index eae592a5f..803d0033d 100644
--- a/pyvo/dal/tests/data/sia/dataset.xml
+++ b/pyvo/dal/tests/data/sia/dataset.xml
@@ -58,6 +58,20 @@
5.2e-07 |
0.000403806 0.000406123 |
+
+ This should not be the dataurl |
+ http://example.com/querydata/image.fits |
+ image/fits |
+ 153280 |
+ |
+ Test |
+ 288.95078924817 |
+ 15.0322239971381 |
+ Test Observation |
+ 3.8e-07 |
+ 5.2e-07 |
+ 0.000403806 0.000406123 |
+
diff --git a/pyvo/dal/tests/data/ssa/result.xml b/pyvo/dal/tests/data/ssa/result.xml
index b30669e79..ad60c5025 100644
--- a/pyvo/dal/tests/data/ssa/result.xml
+++ b/pyvo/dal/tests/data/ssa/result.xml
@@ -209,6 +209,7 @@
1.0976232720625123E-25 | http://vaosa-vm1.aoc.nrao.edu/ivoa-dal/JhuSsapServlet?REQUEST=getData&FORMAT=votable&PubDID=ivo%3A%2F%2Fjhu%2Fsdss%2Fdr6%2Fspec%2F2.5%2380443408220422144 | application/x-votable+xml | SPECTRUM-1.0 | SPECTRUM | 4000 | s | A | 10**(-17) erg s**(-1) cm**(-2) A**(-1) | SDSS J120022.76+004741.46 GALAXY | sdss | SDSS DR6 | ivo://sdss/dr6/spec/2_5/#80443408220422144 | 2001-01-21 11:23:50Z | 6.2.5 | ivo://sdss/dr6/spec/2_5/#80443408220422144 | SDSS 2.5-M SPEC2 v4_5 | OPTICAL | SURVEY | ARCHIVAL | ELTE VO | ivo://jhu/sdss/dr6/spec/2.5#80443408220422144 | PUBLIC | 180.094830 0.794849 | SDSS J120022.76+004741.46 | GALAXY | 0.139797 | 0 | FK5 | 2000 | TAI | 180.094830 0.794849 | |
8.441184510333563E-42 | http://vaosa-vm1.aoc.nrao.edu/ivoa-dal/JhuSsapServlet?REQUEST=getData&FORMAT=votable&PubDID=ivo%3A%2F%2Fjhu%2Fsdss%2Fdr6%2Fspec%2F2.5%2380443407868100608 | application/x-votable+xml | SPECTRUM-1.0 | SPECTRUM | 4000 | s | A | 10**(-17) erg s**(-1) cm**(-2) A**(-1) | SDSS J115918.12+005113.61 GALAXY | sdss | SDSS DR6 | ivo://sdss/dr6/spec/2_5/#80443407868100608 | 2001-01-21 11:23:50Z | 6.2.5 | ivo://sdss/dr6/spec/2_5/#80443407868100608 | SDSS 2.5-M SPEC2 v4_5 | OPTICAL | SURVEY | ARCHIVAL | ELTE VO | ivo://jhu/sdss/dr6/spec/2.5#80443407868100608 | PUBLIC | 179.825520 0.853781 | SDSS J115918.12+005113.61 | GALAXY | 0.0770442 | 0 | FK5 | 2000 | TAI | 179.825520 0.853781 | |
8.441184510333563E-42 | http://vaosa-vm1.aoc.nrao.edu/ivoa-dal/JhuSsapServlet?REQUEST=getData&FORMAT=votable&PubDID=ivo%3A%2F%2Fjhu%2Fsdss%2Fdr6%2Fspec%2F2.5%2380442261136998400 | application/x-votable+xml | SPECTRUM-1.0 | SPECTRUM | 4000 | s | A | 10**(-17) erg s**(-1) cm**(-2) A**(-1) | SDSS J115918.12+005113.61 GALAXY | sdss | SDSS DR6 | ivo://sdss/dr6/spec/2_5/#80442261136998400 | 2000-04-29 03:22:00Z | 6.2.5 | ivo://sdss/dr6/spec/2_5/#80442261136998400 | SDSS 2.5-M SPEC2 v4_5 | OPTICAL | SURVEY | ARCHIVAL | ELTE VO | ivo://jhu/sdss/dr6/spec/2.5#80442261136998400 | PUBLIC | 179.825520 0.853781 | SDSS J115918.12+005113.61 | GALAXY | 0.0770941 | 0 | FK5 | 2000 | TAI | 179.825520 0.853781 | |
+8.441184510333563E-42 | http://vaosa-vm1.aoc.nrao.edu/ivoa-dal/JhuSsapServlet?REQUEST=getData&FORMAT=votable&PubDID=ivo%3A%2F%2Fjhu%2Fsdss%2Fdr6%2Fspec%2F2.5%2380442261136998400 | application/x-votable+xml | SPECTRUM-1.0 | SPECTRUM | 4000 | s | A | 10**(-17) erg s**(-1) cm**(-2) A**(-1) | SDSS J115918.12+005113.61 GALAXY | sdss | SDSS DR6 | ivo://sdss/dr6/spec/2_5/#80442261136998400 | | 6.2.5 | ivo://sdss/dr6/spec/2_5/#80442261136998400 | SDSS 2.5-M SPEC2 v4_5 | OPTICAL | SURVEY | ARCHIVAL | ELTE VO | ivo://jhu/sdss/dr6/spec/2.5#80442261136998400 | PUBLIC | 179.825520 0.853781 | SDSS J115918.12+005113.61 | GALAXY | 0.0770941 | 0 | FK5 | 2000 | TAI | 179.825520 0.853781 | |
diff --git a/pyvo/dal/tests/test_sia.py b/pyvo/dal/tests/test_sia.py
index 7356f0d4b..7197124bf 100644
--- a/pyvo/dal/tests/test_sia.py
+++ b/pyvo/dal/tests/test_sia.py
@@ -61,9 +61,13 @@ class TestSIAService:
@pytest.mark.filterwarnings("ignore::astropy.io.votable.exceptions.W42")
@pytest.mark.filterwarnings("ignore::astropy.io.votable.exceptions.W49")
def test_search(self):
- service = SIAService('http://example.com/sia')
+ url = 'http://example.com/sia'
+ service = SIAService(url)
+ assert service.baseurl == url
results = service.search(pos=(288, 15))
result = results[0]
_test_result(result)
+
+ assert results[1].dateobs is None
diff --git a/pyvo/dal/tests/test_ssa.py b/pyvo/dal/tests/test_ssa.py
index 1570eea77..9c78eee60 100644
--- a/pyvo/dal/tests/test_ssa.py
+++ b/pyvo/dal/tests/test_ssa.py
@@ -33,7 +33,7 @@ def callback(request, context):
@pytest.mark.filterwarnings("ignore::astropy.io.votable.exceptions.W42")
def test_search():
results = search('http://example.com/ssa', pos=(0.0, 0.0), diameter=1.0)
- assert len(results) == 35
+ assert len(results) == 36
class TestSSAService:
@@ -44,4 +44,5 @@ def test_search(self):
results = service.search(pos=(0.0, 0.0), diameter=1.0)
- assert len(results) == 35
+ assert len(results) == 36
+ assert results[35].dateobs is None