Skip to content

Commit 7f8cfad

Browse files
committed
add changelog and suggestions
1 parent 4adb6b9 commit 7f8cfad

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

changelog/3852.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix failing of fetching of the indexed JSOCResponses using `Fido.fetch`.

sunpy/net/fido_factory.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
from parfive import Downloader, Results
1616

17+
import warnings
18+
1719
from sunpy.util.datatype_factory_base import BasicRegistrationFactory
1820
from sunpy.util.datatype_factory_base import NoMatchError
1921
from sunpy.util.datatype_factory_base import MultipleMatchError
@@ -25,6 +27,8 @@
2527
from sunpy.net import attr
2628
from sunpy.net import attrs as a
2729

30+
from sunpy.util.exceptions import SunpyUserWarning
31+
2832
__all__ = ['Fido', 'UnifiedResponse', 'UnifiedDownloaderFactory']
2933

3034

@@ -91,13 +95,19 @@ def _handle_record_slice(self, client_resp, record_slice):
9195

9296
# Make sure we always have an iterable, as most of the response objects
9397
# expect one.
94-
resp = list(client_resp[record_slice])
95-
98+
if isinstance(record_slice, int):
99+
resp = [client_resp[record_slice]]
100+
else:
101+
resp = client_resp[record_slice]
96102
# Reconstruct a response object with the sub-indexed records.
97103
ret = resp_type(resp)
98104
# Make sure we pass the client back out again.
99105
ret.client = client_resp.client
100106

107+
warnings.warn("Downloading of sliced results is not supported. "
108+
"All the files present in the original response will be downloaded.",
109+
SunpyUserWarning)
110+
101111
return ret
102112

103113
def __getitem__(self, aslice):

sunpy/net/jsoc/jsoc.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def __init__(self, table=None):
4444
self.requests = table[0].requests
4545
else:
4646
self.table = table
47-
self.query_args = None
48-
self.requests = None
47+
self.query_args = table.query_args if hasattr(table, 'query_args') else None
48+
self.requests = table.requests if hasattr(table, 'requests') else None
4949

5050
def __str__(self):
5151
return str(self.table)
@@ -63,10 +63,13 @@ def __len__(self):
6363
return len(self.table)
6464

6565
def __getitem__(self, item):
66-
resp = type(self)(self.table[item])
67-
resp.query_args = self.query_args
68-
resp.requests = self.requests
69-
return resp
66+
if isinstance(item, int):
67+
item = slice(item, item+1)
68+
ret = type(self)(self.table[item])
69+
ret.query_args = self.query_args
70+
ret.requests = self.requests
71+
72+
return ret
7073

7174
def __iter__(self):
7275
return (t for t in [self])

sunpy/net/tests/test_fido.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ def test_slice_jsoc():
487487
res = Fido.search(a.Time(tstart, tend), a.jsoc.Series('hmi.M_45s'),
488488
a.jsoc.Notify('jsoc@cadair.com'))
489489

490-
result = Fido.fetch(res[0, 0])
491-
assert isinstance(result, Results)
490+
with pytest.warns(SunpyUserWarning):
491+
result = Fido.fetch(res[0, 0])
492+
assert isinstance(result, Results)
492493

493-
result = Fido.fetch(res[0, 0:2])
494-
assert isinstance(result, Results)
495-
494+
result = Fido.fetch(res[0, 0:2])
495+
assert isinstance(result, Results)

0 commit comments

Comments
 (0)