Repository: sunpy/sunpy

Issue:
Make it possible to pass kwargs to `VSOClient.get()` inside database.download
Both through `fetch` and `download`. Mainly passing `methods` so that RICE compressed data can be downloaded.



Discussion:
I have a local fix for this but there would be a merge conflict with #1165 if I submitted a new PR for it now, so I will wait until #1165 has been merged.

@Cadair @derdon Can you please elaborate what you want to achieve here?


Resolving patch:
diff --git a/sunpy/database/database.py b/sunpy/database/database.py
--- a/sunpy/database/database.py
+++ b/sunpy/database/database.py
@@ -307,12 +307,21 @@ def commit(self):
         """
         self.session.commit()
 
-    def _download_and_collect_entries(self, query_result, client=None,
-            path=None, progress=False):
+    def _download_and_collect_entries(self, query_result, **kwargs):
+
+        client = kwargs.pop('client', None)
+        path = kwargs.pop('path', None)
+        progress = kwargs.pop('progress', False)
+        methods = kwargs.pop('methods', ('URL-FILE_Rice', 'URL-FILE'))
+
+        if kwargs:
+            k, v = kwargs.popitem()
+            raise TypeError('unexpected keyword argument {0!r}'.format(k))
+
         if client is None:
             client = VSOClient()
 
-        paths = client.get(query_result, path).wait(progress=progress)
+        paths = client.get(query_result, path, methods).wait(progress=progress)
 
         for (path, block) in zip(paths, query_result):
             qr_entry = tables.DatabaseEntry._from_query_result_block(block)
@@ -354,20 +363,18 @@ def download(self, *query, **kwargs):
         """
         if not query:
             raise TypeError('at least one attribute required')
-        client = kwargs.pop('client', None)
-        path = kwargs.pop('path', None)
-        progress = kwargs.pop('progress', False)
-        if kwargs:
-            k, v = kwargs.popitem()
-            raise TypeError('unexpected keyword argument {0!r}'.format(k))
+        
+        client = kwargs.get('client', None)
         if client is None:
             client = VSOClient()
         qr = client.query(*query)
+
         # don't do anything if querying the VSO results in no data
         if not qr:
             return
+
         entries = list(self._download_and_collect_entries(
-            qr, client, path, progress))
+            qr, **kwargs))
         dump = serialize.dump_query(and_(*query))
         (dump_exists,), = self.session.query(
             exists().where(tables.JSONDump.dump == tables.JSONDump(dump).dump))
@@ -410,16 +417,13 @@ def fetch(self, *query, **kwargs):
         """
         if not query:
             raise TypeError('at least one attribute required')
-        path = kwargs.pop('path', None)
-        if kwargs:
-            k, v = kwargs.popitem()
-            raise TypeError('unexpected keyword argument {0!r}'.format(k))
+        
         dump = serialize.dump_query(and_(*query))
         (dump_exists,), = self.session.query(
             exists().where(tables.JSONDump.dump == tables.JSONDump(dump).dump))
         if dump_exists:
             return self.query(*query)
-        return self.download(*query, path=path)
+        return self.download(*query, **kwargs)
 
     def query(self, *query, **kwargs):
         """
@@ -685,7 +689,7 @@ def download_from_vso_query_result(self, query_result, client=None,
         if not query_result:
             return
         self.add_many(self._download_and_collect_entries(
-            query_result, client, path, progress))
+            query_result, client=client, path=path, progress=progress))
 
     def add_from_vso_query_result(self, query_result,
             ignore_already_added=False):


Test patch:
diff --git a/sunpy/database/tests/test_database.py b/sunpy/database/tests/test_database.py
--- a/sunpy/database/tests/test_database.py
+++ b/sunpy/database/tests/test_database.py
@@ -718,11 +718,6 @@ def test_download_missing_arg(database):
         database.download()
 
 
-def test_download_unexpected_kwarg(database):
-    with pytest.raises(TypeError):
-        database.download(vso.attrs.Source('SOHO'), foo=42)
-
-
 @pytest.mark.online
 def test_download_empty_query_result(database, empty_query):
     database.download(*empty_query)
@@ -767,11 +762,6 @@ def test_fetch_missing_arg(database):
         database.fetch()
 
 
-def test_fetch_unexpected_kwarg(database):
-    with pytest.raises(TypeError):
-        database.fetch(vso.attrs.Source('SOHO'), foo=42)
-
-
 @pytest.mark.online
 def test_fetch(database, download_query, tmpdir):
     assert len(database) == 0