Skip to content

Commit e2db773

Browse files
authored
Merge pull request #3199 from cds-astro/fix-use-left-join-in-measurement-tables
fix: use left join when adding tables instead of inner join
2 parents 9e2ab6c + 3e9ff61 commit e2db773

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

CHANGES.rst

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ ipac.nexsci.nasa_exoplanet_archive
2121

2222
- Fixed InvalidTableError for DI_STARS_EXEP and TD tables. [#3189]
2323

24+
simbad
25+
^^^^^^
26+
27+
- fix: when adding a measurement table in the votable_fields, if a measurement table is
28+
empty for an object, there will now be a line with masked values instead of no line in
29+
the result [#3199]
30+
2431
xmatch
2532
^^^^^^
2633

astroquery/simbad/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def _add_table_to_output(self, table):
347347
self.columns_in_output += [_Column(table, column, alias)
348348
for column, alias in zip(columns, alias)]
349349
self.joins += [_Join(table, _Column("basic", link["target_column"]),
350-
_Column(table, link["from_column"]))]
350+
_Column(table, link["from_column"]), "LEFT JOIN")]
351351

352352
def add_votable_fields(self, *args):
353353
"""Add columns to the output of a SIMBAD query.

astroquery/simbad/tests/test_simbad.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def test_add_table_to_output(monkeypatch):
214214
simbad_instance._add_table_to_output("mesDiameter")
215215
assert simbad.core._Join("mesdiameter",
216216
simbad.core._Column("basic", "oid"),
217-
simbad.core._Column("mesdiameter", "oidref")
217+
simbad.core._Column("mesdiameter", "oidref"), "LEFT JOIN"
218218
) in simbad_instance.joins
219219
assert simbad.core._Column("mesdiameter", "bibcode", "mesdiameter.bibcode"
220220
) in simbad_instance.columns_in_output

astroquery/simbad/tests/test_simbad_remote.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ def test_query_object(self):
119119
result = self.simbad.query_object("NGC [0-9]*", wildcard=True)
120120
assert all(matched_id.startswith("NGC") for matched_id in result["matched_id"].data.data)
121121

122+
def test_query_object_with_measurement_table(self):
123+
# regression for #3197
124+
self.simbad.reset_votable_fields()
125+
self.simbad.add_votable_fields("mesdistance")
126+
vega = self.simbad.query_object("vega")
127+
# there is one response line
128+
assert len(vega) == 1
129+
# even if the measurement table is empty
130+
assert bool(vega["mesdistance.dist"][0].mask)
131+
122132
def test_query_criteria(self):
123133
simbad_instance = Simbad()
124134
simbad_instance.add_votable_fields("otype")
@@ -199,7 +209,8 @@ def test_add_votable_fields(self):
199209
# tables also require a join
200210
assert _Join("otypes",
201211
_Column("basic", "oid"),
202-
_Column("otypes", "oidref")) == simbad_instance.joins[0]
212+
_Column("otypes", "oidref"),
213+
"LEFT JOIN") == simbad_instance.joins[0]
203214
# tables that have been renamed should warn
204215
with pytest.warns(DeprecationWarning, match="'iue' has been renamed 'mesiue'.*"):
205216
simbad_instance.add_votable_fields("IUE")

docs/simbad/simbad.rst

+66
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,72 @@ And the columns in the output can be reset to their default value with
662662
A detailed description on the ways to add fluxes is available in the
663663
:ref:`optical filters` section.
664664

665+
Measurement fields vs. Basic fields
666+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
667+
668+
Some field names start with ``mes``. These denote what SIMBAD calls a
669+
"measurement table". These tables store the history on past measurements of a physical
670+
parameter for each object.
671+
672+
Let's look at the star ``HD 200207`` with the parallax measurements table ``mesplx``:
673+
674+
.. doctest-remote-data::
675+
676+
>>> from astroquery.simbad import Simbad
677+
>>> simbad = Simbad()
678+
>>> simbad.add_votable_fields("mesplx")
679+
>>> hd_200207 = simbad.query_object("HD 200207")
680+
>>> hd_200207[["main_id", "mesplx.plx", "mesplx.plx_err", "mesplx.bibcode"]]
681+
<Table length=5>
682+
main_id mesplx.plx mesplx.plx_err mesplx.bibcode
683+
mas mas
684+
object float32 float32 object
685+
--------- ---------- -------------- -------------------
686+
HD 200207 3.4084 0.0195 2020yCat.1350....0G
687+
HD 200207 3.4552 0.0426 2018yCat.1345....0G
688+
HD 200207 3.35 0.76 1997A&A...323L..49P
689+
HD 200207 3.72 0.62 2007A&A...474..653V
690+
HD 200207 3.25 0.22 2016A&A...595A...2G
691+
692+
This field adds one line per parallax measurement: five articles have measured it
693+
for this star.
694+
695+
If you are only interested in the most precise measure recorded by the SIMBAD team, some
696+
measurements fields have an equivalent in the basic fields. These fields only give one
697+
line per object with the most precise currently known value:
698+
699+
+-------------------+---------------+
700+
| measurement field | basic field |
701+
+===================+===============+
702+
| mesplx | parallax |
703+
+-------------------+---------------+
704+
| mespm | propermotions |
705+
+-------------------+---------------+
706+
| messpt | sp |
707+
+-------------------+---------------+
708+
| mesvelocities | velocity |
709+
+-------------------+---------------+
710+
711+
Here, ``mesplx`` has an equivalent in the basic fields so we could have done:
712+
713+
.. doctest-remote-data::
714+
715+
>>> from astroquery.simbad import Simbad
716+
>>> simbad = Simbad()
717+
>>> simbad.add_votable_fields("parallax")
718+
>>> hd_200207 = simbad.query_object("HD 200207")
719+
>>> hd_200207[["main_id", "plx_value", "plx_err", "plx_bibcode"]]
720+
<Table length=1>
721+
main_id plx_value plx_err plx_bibcode
722+
mas mas
723+
object float64 float32 object
724+
--------- --------- ------- -------------------
725+
HD 200207 3.4084 0.0195 2020yCat.1350....0G
726+
727+
And we only have one line per object with the value selected by SIMBAD's team.
728+
729+
Thus, choosing to add a measurement field or a basic field depends on your goal.
730+
665731
Additional criteria
666732
-------------------
667733

0 commit comments

Comments
 (0)