Repository: astropy/pyvo
Pull request #222 (2020-04-18 23:38:34)

Sia2 kwargs
#221 

cbanek: Guessing the build break is some kind of upstream future votable thing in astropy?
tomdonaldson: > Guessing the build break is some kind of upstream future votable thing in astropy?

Yes, @cbanek .  Surely this is due to https://github.com/astropy/astropy/pull/9505, which will be released soon with astropy 4.1.

Whether these failures get fixed here to pass with both `byte` and `str` values, we should probably think about whether we have other coordination to do with respect to that change.  I.e., which pyvo versions should pass testing with both astropy 4.0 and 4.1?
codecov[bot]: # [Codecov](https://codecov.io/gh/astropy/pyvo/pull/222?src=pr&el=h1) Report
> Merging [#222](https://codecov.io/gh/astropy/pyvo/pull/222?src=pr&el=desc) into [master](https://codecov.io/gh/astropy/pyvo/commit/9d527e1caffaedf15a9b3580c31b26be8fff40e7&el=desc) will **increase** coverage by `0.04%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/astropy/pyvo/pull/222/graphs/tree.svg?width=650&height=150&src=pr&token=Mynyo9xoPZ)](https://codecov.io/gh/astropy/pyvo/pull/222?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #222      +/-   ##
==========================================
+ Coverage   72.19%   72.24%   +0.04%     
==========================================
  Files          42       42              
  Lines        4478     4486       +8     
==========================================
+ Hits         3233     3241       +8     
  Misses       1245     1245              
```


| [Impacted Files](https://codecov.io/gh/astropy/pyvo/pull/222?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pyvo/dal/sia2.py](https://codecov.io/gh/astropy/pyvo/pull/222/diff?src=pr&el=tree#diff-cHl2by9kYWwvc2lhMi5weQ==) | `70.98% <100.00%> (+0.81%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/astropy/pyvo/pull/222?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/astropy/pyvo/pull/222?src=pr&el=footer). Last update [9d527e1...b810aa9](https://codecov.io/gh/astropy/pyvo/pull/222?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

andamian: All green now! @funbaker do you have time to take a look? Thanks
andamian: @funbaker - anything else needed for the approval?

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 7d93e2a..ed9ce8f 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -9,6 +9,8 @@
 
 - Add support for SIAv2. [#206]
 
+- Add kwargs to sia2. [#222]
+
 1.0 (2019-09-20)
 ================
 
diff --git a/pyvo/dal/sia2.py b/pyvo/dal/sia2.py
index 1f6a0b4..4faef97 100644
--- a/pyvo/dal/sia2.py
+++ b/pyvo/dal/sia2.py
@@ -82,6 +82,11 @@ res_format : single or list of strings
     specifies response format(s).
 max_records : int
     allows the client to limit the number or records in the response
+**kwargs : custom query parameters
+    single or a list of values (or tuples for intervals) custom query
+    parameters that a specific service accepts. The values of the
+    parameters need to follow the SIAv2 format and represent the
+    appropriate quantities (where applicable).
 """
 
 
@@ -90,7 +95,8 @@ def search(url, pos=None, band=None, time=None, pol=None,
            spectral_resolving_power=None, exptime=None,
            timeres=None, publisher_did=None, facility=None, collection=None,
            instrument=None, data_type=None, calib_level=None,
-           target_name=None, res_format=None, maxrec=None, session=None):
+           target_name=None, res_format=None, maxrec=None, session=None,
+           **kwargs):
     """
     submit a simple SIA query to a SIAv2 compatible service
 
@@ -113,7 +119,7 @@ def search(url, pos=None, band=None, time=None, pol=None,
                           instrument=instrument, data_type=data_type,
                           calib_level=calib_level, target_name=target_name,
                           res_format=res_format, maxrec=maxrec,
-                          session=session)
+                          session=session, **kwargs)
 
 
 search.__doc__ = search.__doc__.replace('_SIA2_PARAMETERS',
@@ -173,7 +179,8 @@ class SIAService(DALService, AvailabilityMixin, CapabilityMixin):
                spectral_resolving_power=None, exptime=None,
                timeres=None, publisher_did=None, facility=None, collection=None,
                instrument=None, data_type=None, calib_level=None,
-               target_name=None, res_format=None, maxrec=None, session=None):
+               target_name=None, res_format=None, maxrec=None, session=None,
+               **kwargs):
         """
         Performs a SIAv2 search against a SIAv2 service
 
@@ -193,7 +200,7 @@ class SIAService(DALService, AvailabilityMixin, CapabilityMixin):
                         instrument=instrument, data_type=data_type,
                         calib_level=calib_level, target_name=target_name,
                         res_format=res_format, maxrec=maxrec,
-                        session=session).execute()
+                        session=session, **kwargs).execute()
 
 
 class SIAQuery(DALQuery, AxisParamMixin):
@@ -209,7 +216,7 @@ class SIAQuery(DALQuery, AxisParamMixin):
                  facility=None, collection=None,
                  instrument=None, data_type=None, calib_level=None,
                  target_name=None, res_format=None, maxrec=None,
-                 session=None):
+                 session=None, **kwargs):
         """
         initialize the query object with a url and the given parameters
 
@@ -305,6 +312,16 @@ class SIAQuery(DALQuery, AxisParamMixin):
         for rf in _tolist(res_format):
             self.res_format.add(rf)
 
+        for name, value in kwargs.items():
+            custom_arg = []
+            for kw in _tolist(value):
+                if isinstance(kw, tuple):
+                    val = '{} {}'.format(kw[0], kw[1])
+                else:
+                    val = str(kw)
+                custom_arg.append(val)
+            self[name] = custom_arg
+
         self.maxrec = maxrec
 
     __init__.__doc__ = \


Test patch:
diff --git a/pyvo/dal/tests/test_sia2.py b/pyvo/dal/tests/test_sia2.py
index 315539e..0bbf228 100644
--- a/pyvo/dal/tests/test_sia2.py
+++ b/pyvo/dal/tests/test_sia2.py
@@ -134,3 +134,12 @@ class TestSIAQuery():
 
         query.maxrec = 1000
         assert query['MAXREC'] == '1000'
+
+        query = SIAQuery('someurl', custom_param=23)
+        assert query['custom_param'] == ['23']
+
+        query['custom_param'].append('-Inf 0')
+        assert query['custom_param'] == ['23', '-Inf 0']
+
+        query = SIAQuery('someurl', custom_param=[('-Inf', 0), (2, '+Inf')])
+        assert query['custom_param'] == ['-Inf 0', '2 +Inf']