Skip to content

Commit

Permalink
Replace vectorize(decode()) with np.char.decode as suggested by @saimn.
Browse files Browse the repository at this point in the history
It seems that vectorize isn't working properly with chararray anyway?
  • Loading branch information
jehturner committed Feb 21, 2020
1 parent f741b2f commit 2ec355a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions astrodata/fits.py
Expand Up @@ -417,11 +417,12 @@ def asdftablehdu_to_wcs(hdu):
# data, in which case we just extract unmodified bytes from the table.
if colarr.dtype.kind in ('U', 'S'):
sep = os.linesep
# Not sure whether io.fits ever produces 'S' on Py 3, but just in
# case: join lines as str & avoid a TypeError with unicode linesep;
# could also use astype('U') but it assumes an encoding implicitly.
# Just in case io.fits ever produces 'S' on Py 3 (not the default):
# join lines as str & avoid a TypeError with unicode linesep; could
# also use astype('U') but it assumes an encoding implicitly.
if colarr.dtype.kind == 'S' and not isinstance(sep, bytes):
colarr = np.vectorize(lambda b: b.decode('ascii'))(colarr)
colarr = np.char.decode(np.char.rstrip(colarr),
encoding='ascii')
wcsbuf = sep.join(colarr).encode('ascii')
else:
wcsbuf = colarr.tobytes()
Expand Down

0 comments on commit 2ec355a

Please sign in to comment.