Skip to content

Commit d869005

Browse files
committed
Actually the dtype constructor blows up on zero-width fields *except* when using the list-based constructor. Oh well. See numpy/numpy#2196; I don't think arbitrary offsets is much of an issue here (that only matters for ASCII tables, to which this code doesn't apply).
1 parent 25848e9 commit d869005

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

‎astropy/io/fits/hdu/table.py‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,9 +1476,9 @@ def _binary_table_byte_swap(data):
14761476

14771477
orig_dtype = data.dtype
14781478

1479-
# We use the dict format for the new dtype because this actually contains
1480-
# more information (in particular field offsets) than the .descr format
1481-
new_dtype = {}
1479+
names = []
1480+
formats = []
1481+
14821482
to_swap = []
14831483

14841484
if sys.byteorder == 'little':
@@ -1489,23 +1489,21 @@ def _binary_table_byte_swap(data):
14891489
for idx, name in enumerate(orig_dtype.names):
14901490
field = _get_recarray_field(data, idx)
14911491

1492-
new_dtype[name] = field_descr = orig_dtype.fields[name]
1492+
field_dtype = orig_dtype.fields[name][0]
1493+
names.append(name)
1494+
formats.append(field_dtype)
14931495

14941496
if isinstance(field, chararray.chararray):
14951497
continue
14961498

1497-
field_dtype = field_descr[0]
1498-
14991499
# only swap unswapped
15001500
# must use field_dtype.base here since for multi-element dtypes,
15011501
# the .str with be '|V<N>' where <N> is the total bytes per element
15021502
if field.itemsize > 1 and field_dtype.base.str[0] in swap_types:
15031503
to_swap.append(field)
1504-
field_dtype = field_dtype.newbyteorder()
1505-
1506-
# Override the new_dtype using the new byteswapped dtype for this
1507-
# field
1508-
new_dtype[name] = (field_dtype,) + field_descr[1:]
1504+
# Override the dtype for this field in the new record dtype with
1505+
# the byteswapped version
1506+
formats[-1] = field_dtype.newbyteorder()
15091507

15101508
# deal with var length table
15111509
recformat = data.columns._recformats[idx]
@@ -1519,7 +1517,7 @@ def _binary_table_byte_swap(data):
15191517
for arr in reversed(to_swap):
15201518
arr.byteswap(True)
15211519

1522-
data.dtype = np.dtype(new_dtype)
1520+
data.dtype = np.dtype(list(zip(names, formats)))
15231521

15241522
yield data
15251523

0 commit comments

Comments
 (0)