Skip to content

Commit

Permalink
Merge pull request #7630 from meeseeksmachine/auto-backport-of-pr-762…
Browse files Browse the repository at this point in the history
…7-on-5.1

Backport PR #7627 on branch 5.1 (Fix bug when converting results from the HEKClient )
  • Loading branch information
nabobalis committed May 15, 2024
2 parents beeda3b + dd7d121 commit ee39fb0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/7627.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug where conversion of results from the HEKClient to Astropy Time failed when some values where empty or missing for the values of event_strattime, event_endtime or event_peaktime
9 changes: 6 additions & 3 deletions sunpy/net/hek/hek.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import inspect
from itertools import chain

import numpy.ma

import astropy.table
from astropy.table import Row

Expand Down Expand Up @@ -91,9 +93,10 @@ def _parse_times(table):
# All time columns from https://www.lmsal.com/hek/VOEvent_Spec.html
time_keys = ['event_endtime', 'event_starttime', 'event_peaktime']
for tkey in time_keys:
if tkey in table.colnames and not any(time == "" for time in table[tkey]):
table[tkey] = parse_time(table[tkey])
table[tkey].format = 'iso'
if tkey in table.colnames:
table[tkey] = [
(parse_time(time, format='iso') if time else numpy.ma.masked) for time in table[tkey]
]
return table

def search(self, *args, **kwargs):
Expand Down
10 changes: 10 additions & 0 deletions sunpy/net/hek/tests/test_hek.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy

import numpy as np
import pytest

from astropy.time import Time
Expand Down Expand Up @@ -218,3 +219,12 @@ def test_query_multiple_operators():
attrs.hek.FL.GOESCls > "M1.0",
attrs.hek.OBS.Observatory == "GOES")
assert len(results) == 7


@pytest.mark.remote_data
def test_missing_times():
# Check for https://github.com/sunpy/sunpy/pull/7627#issuecomment-2113451964
client = hek.HEKClient()
results = client.search(attrs.Time('2024-05-10', '2024-05-12'), attrs.hek.AR.NOAANum == 13664)
assert isinstance(results["event_peaktime"][0], np.ma.core.MaskedConstant)
assert results["event_peaktime"][1].isot == '2024-05-10T16:08:00.000'

0 comments on commit ee39fb0

Please sign in to comment.