Skip to content

Commit 6e480ef

Browse files
committed
Correctly support IPAC table null values
When 'null' occurs in the NULL row it now generates a fill_value entry that will create a True mask if 'null' occurs in the data. Closes #361 (Issue with null values in IPAC tables) and addresses half of issue #463 (astropy.io.ascii and astropy.io.votable fail with this table).
1 parent e581c53 commit 6e480ef

3 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎astropy/io/ascii/ipac.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,16 @@ def get_cols(self, lines):
151151
if len(header_vals) > 2:
152152
col.units = header_vals[2][i].strip() # Can't strip dashes here
153153
if len(header_vals) > 3:
154+
# The IPAC null value corresponds to the io.ascii bad_value.
155+
# In this case there isn't a fill_value defined, so just put
156+
# in the minimal entry that is sure to convert properly to the
157+
# required type.
158+
#
159+
# Strip spaces but not dashes (not allowed in NULL row per
160+
# https://github.com/astropy/astropy/issues/361)
154161
null = header_vals[3][i].strip()
155-
if null.lower() != 'null':
156-
col.null = null # Can't strip dashes here
157-
if issubclass(col.type, core.FloatType):
158-
fillval = 'nan'
159-
else:
160-
fillval = '-999'
161-
self.data.fill_values.append((col.null, fillval, col.name))
162+
fillval = '' if issubclass(col.type, core.StrType) else '0'
163+
self.data.fill_values.append((null, fillval, col.name))
162164
start = col.end + 1
163165
cols.append(col)
164166

‎astropy/io/ascii/tests/t/ipac.dat‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
| ra | dec | sai |-----v2---| sptype |
88
| real | real | int | real | char |
99
| unit | unit | unit | unit | ergs |
10-
| null | null | null | null | -999 |
11-
2.09708 29.09056 73765 2.06000 B8IVpMnHg
10+
| null | null | -999 | null | -999 |
11+
null 29.09056 -999 2.06000 -999
1212
12345678901234567890123456789012345678901234567890123456789012345

‎astropy/io/ascii/tests/test_read.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ def test_masking_Cds():
252252
assert_true(not data['Fit'].mask[0])
253253

254254

255+
def test_null_Ipac():
256+
f = 't/ipac.dat'
257+
testfile = get_testfiles(f)
258+
data = asciitable.read(f, **testfile['opts'])
259+
mask = np.array([(True, False, True, False, True),
260+
(False, False, False, False, False)],
261+
dtype=[('ra', '|b1'), ('dec', '|b1'), ('sai', '|b1'),
262+
('v2', '|b1'), ('sptype', '|b1')])
263+
assert np.all(data.mask == mask)
264+
265+
255266
def test_set_guess_kwarg():
256267
"""Read a file using guess with one of the typical guess_kwargs explicitly set."""
257268
data = asciitable.read('t/space_delim_no_header.dat',

0 commit comments

Comments
 (0)