Skip to content

Commit

Permalink
Add test of custom reader class that sets col.dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
taldcroft committed Jun 28, 2021
1 parent fd06dc1 commit d1503e5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions astropy/io/ascii/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


from io import StringIO
import numpy as np

from astropy.io import ascii

Expand Down Expand Up @@ -49,3 +50,30 @@ def test_ipac_read_types():
ascii.StrType]
for (col, expected_type) in zip(reader.cols, types):
assert_equal(col.type, expected_type)


def test_col_dtype_in_custom_class():
"""Test code in BaseOutputter._convert_vals to handle Column.dtype
attribute. See discussion in #11895."""
dtypes = [np.float32, np.int8, np.int16]

class TestDtypeHeader(ascii.BasicHeader):
def get_cols(self, lines):
super().get_cols(lines)
for col, dtype in zip(self.cols, dtypes):
col.dtype = dtype

class TestDtype(ascii.Basic):
"""
Basic table Data Reader with data type alternating float32, int8
"""
header_class = TestDtypeHeader

txt = """
a b c
1 2 3
"""
reader = ascii.get_reader(TestDtype)
t = reader.read(txt)
for col, dtype in zip(t.itercols(), dtypes):
assert col.dtype.type is dtype

0 comments on commit d1503e5

Please sign in to comment.