Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APE6 example does not round trip #48

Closed
pllim opened this issue Dec 12, 2018 · 1 comment
Closed

APE6 example does not round trip #48

pllim opened this issue Dec 12, 2018 · 1 comment

Comments

@pllim
Copy link
Member

pllim commented Dec 12, 2018

I am trying out an example on APE 6 but I cannot get it to round trip on write/read with Python 3.7.1, Astropy 3.1, and Numpy 1.15.4. I am not sure if there is a policy to ensure APE examples always work, but I am reporting this anyway FWIW.

>>> from astropy.table import Table
>>> from collections import OrderedDict
>>> import astropy.units as u
>>> t = Table([[1, 4], [2, 3]], names=['a', 'b'])
>>> t.meta['keywords'] = OrderedDict([('z_key1', 'val1'), ('a_key2', 'val2')])
>>> t.meta['comments'] = ['Comment 1', 'Comment 2', 'Comment 3']
>>> t['a'].unit = u.m / u.s
>>> t['a'].format = '%5.2f'
>>> t['a'].description = 'Column A'
>>> t['b'].meta = dict(column_meta={'a':1, 'b': 2})
>>> In [13]: t
<Table length=2>
  a     b
m / s
int32 int32
----- -----
 1.00     2
 4.00     3
>>> t.meta
OrderedDict([('keywords',
              OrderedDict([('z_key1', 'val1'), ('a_key2', 'val2')])),
             ('comments', ['Comment 1', 'Comment 2', 'Comment 3'])])
>>> t.write('ztmp.ecsv')
>>> t2 = Table.read('ztmp.ecsv')
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
...\astropy\io\ascii\core.py in _convert_va
ls(self, cols)
    952                 try:
--> 953                     converter_func, converter_type = col.converters[0]
    954                     if not issubclass(converter_type, col.type):

IndexError: list index out of range

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-15-eb21516157bd> in <module>
----> 1 t2 = Table.read('ztmp.ecsv')

...\astropy\table\table.py in read(cls, *ar
gs, **kwargs)
   2546         # RST table and inserts at the end of the docstring.  DO NOT REM
OVE.
   2547
-> 2548         out = io_registry.read(cls, *args, **kwargs)
   2549         # For some readers (e.g., ascii.ecsv), the returned `out` class
is not
   2550         # guaranteed to be the same as the desired output `cls`.  If so,


...\astropy\io\registry.py in read(cls, for
mat, *args, **kwargs)
    515
    516         reader = get_reader(format, cls)
--> 517         data = reader(*args, **kwargs)
    518
    519         if not isinstance(data, cls):

...\astropy\io\ascii\connect.py in io_read(
format, filename, **kwargs)
     35     from .ui import read
     36     format = re.sub(r'^ascii\.', '', format)
---> 37     return read(filename, format=format, **kwargs)
     38
     39

...\astropy\io\ascii\ui.py in read(table, g
uess, **kwargs)
    402         else:
    403             reader = get_reader(**new_kwargs)
--> 404             dat = reader.read(table)
    405             _read_trace.append({'kwargs': copy.deepcopy(new_kwargs),
    406                                 'Reader': reader.__class__,

...\astropy\io\ascii\core.py in read(self,
table)
   1195         if hasattr(self.header, 'table_meta'):
   1196             self.meta['table'].update(self.header.table_meta)
-> 1197         table = self.outputter(cols, self.meta)
   1198         self.cols = self.header.cols
   1199

...\astropy\io\ascii\ecsv.py in __call__(se
lf, cols, meta)
    190     def __call__(self, cols, meta):
    191         # Convert to a Table with all plain Column subclass columns
--> 192         out = super().__call__(cols, meta)
    193
    194         # If mixin columns exist (based on the special '__mixin_columns_
_'

...\astropy\io\ascii\core.py in __call__(se
lf, cols, meta)
    982         # Sets col.data to numpy array and col.type to io.ascii Type cla
ss (e.g.
    983         # FloatType) for each col.
--> 984         self._convert_vals(cols)
    985
    986         # If there are any values that were filled and tagged with a mas
k bit then this

...\astropy\io\ascii\core.py in _convert_va
ls(self, cols)
    967                     last_err = err
    968                 except IndexError:
--> 969                     raise ValueError('Column {} failed to convert: {}'.f
ormat(col.name, last_err))
    970
    971

ValueError: Column a failed to convert: invalid literal for int() with base 10:
'1.00'
@taldcroft
Copy link
Member

taldcroft commented Dec 12, 2018

Why oh why did I make such a weird example? Setting an int to have a %5.2 format is just silly, but of course Python2 was "helpful" and let that not break on roundtrip. The following is a fix:

>>> t = Table([[1.0, 4.0], [2, 3]], names=['a', 'b'])

But the bigger question of testing APE6 examples is quite good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants