Skip to content

Sporadic test failure with fast io.ascii reader - #2964

Merged
astrofrog merged 2 commits into
astropy:masterfrom
mdmueller:fix-mac-issue
Nov 3, 2014
Merged

astrofrog merged 2 commits into
astropy:masterfrom
mdmueller:fix-mac-issue

Conversation

@astrofrog

Copy link
Copy Markdown
Member

I'm seeing this test failure from time to time on the Mac Jenkins instance - it's not systematic, so maybe there is a race condition, or something to do with random numbers (haven't checked in detail):

def test_fill_include_exclude_names():
        """
        fill_include_names and fill_exclude_names should filter missing/empty value handling
        in the same way that include_names and exclude_names filter output columns.
        """
        text = """
    A, B, C
    , 1, 2
    3, , 4
    5, 5,
    """
        table = read_csv(text, fill_include_names=['A', 'B'])
        assert table['A'][0] is ma.masked
        assert table['B'][1] is ma.masked
        assert table['C'][2] is not ma.masked # C not in fill_include_names

>       table = read_csv(text, fill_exclude_names=['A', 'B'])

astropy/io/ascii/tests/test_c_reader.py:435: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

table = '\nA, B, C\n, 1, 2\n3, , 4\n5, 5,\n'
kwargs = {'fill_exclude_names': ['A', 'B']}

    def read_csv(table, **kwargs):
>       return _read(table, FastCsv, 'csv', **kwargs)

astropy/io/ascii/tests/test_c_reader.py:81: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

table = '\nA, B, C\n, 1, 2\n3, , 4\n5, 5,\n\n'
Reader = <class 'astropy.io.ascii.fastbasic.FastCsv'>, format = 'csv'
fail_parallel = False, kwargs = {'fill_exclude_names': ['A', 'B']}
reader = <astropy.io.ascii.fastbasic.FastCsv object at 0x10f9cbd90>
t1 = <Table rows=3 names=('A','B','C')>
masked_array(data = [('', '1', 2) ('3', '',...', 'N', 999999),
            dtype = [('A', 'S1'), ('B', 'S1'), ('C', '<i8')])

t2 = <Table rows=3 names=('A','B','C')>
masked_array(data = [('', '1', 2) ('3', '',...', 'N', 999999),
            dtype = [('A', 'S1'), ('B', 'S1'), ('C', '<i8')])

t3 = <Table rows=3 names=('A','B','C')>
masked_array(data = [('', '1', 2) ('3', '',...', 'N', 999999),
            dtype = [('A', 'S1'), ('B', 'S1'), ('C', '<i8')])

t4 = <Table rows=3 names=('A','B','C')>
masked_array(data = [(8070450532247928832, ..., 'N', 999999),
            dtype = [('A', '<i8'), ('B', 'S1'), ('C', '<i8')])

t5 = <Table rows=3 names=('A','B','C')>
masked_array(data = [('', '1', 2) ('3', '',...', 'N', 999999),
            dtype = [('A', 'S1'), ('B', 'S1'), ('C', '<i8')])


    def _read(table, Reader, format, fail_parallel=False, **kwargs):
        # make sure we have a newline so table can't be misinterpreted as a filename
        table += '\n'
        reader = Reader(**kwargs)
        t1 = reader.read(table)
        t2 = reader.read(StringIO(table))
        t3 = reader.read(table.splitlines())
        t4 = ascii.read(table, format=format, guess=False, **kwargs)
        t5 = ascii.read(table, format=format, guess=False, fast_reader=False, **kwargs)
        assert_table_equal(t1, t2)
        assert_table_equal(t2, t3)
>       assert_table_equal(t3, t4)

astropy/io/ascii/tests/test_c_reader.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

t1 = <Table rows=3 names=('A','B','C')>
masked_array(data = [('', '1', 2) ('3', '',...', 'N', 999999),
            dtype = [('A', 'S1'), ('B', 'S1'), ('C', '<i8')])

t2 = <Table rows=3 names=('A','B','C')>
masked_array(data = [(8070450532247928832, ..., 'N', 999999),
            dtype = [('A', '<i8'), ('B', 'S1'), ('C', '<i8')])


    def assert_table_equal(t1, t2):
        assert_equal(len(t1), len(t2))
        assert_equal(t1.colnames, t2.colnames)
        for name in t1.colnames:
            if len(t1) != 0:
>               assert_equal(t1[name].dtype.kind, t2[name].dtype.kind)

astropy/io/ascii/tests/test_c_reader.py:31: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = 'S', b = 'i'

    def assert_equal(a, b):
>       assert a == b
E       assert 'S' == 'i'
E         - S
E         + i

astropy/io/ascii/tests/common.py:41: AssertionError

cc @AmrAS1 @taldcroft

@mdmueller

Copy link
Copy Markdown
Contributor

Hm...at first glance I thought it strange that ascii.read messes up while reader.read doesn't, but then I realized that the latter doesn't receive kwargs. That's not a big deal but I might as well open a PR to fix it for the sake of completeness. Never mind, I just realized thatkwargs is passed in Reader.__init__.

There aren't any random numbers involved, so my guess is this is some problem with memory. The parser has a separate buffer for empty strings, so it could be something to do with that. I'll look closer at the relevant code and see if anything could be problematic.

@jfoster17

Copy link
Copy Markdown
Contributor

I've also run into this test failing (sporadically) when running tests manually.

@mdmueller

Copy link
Copy Markdown
Contributor

Unfortunately I have no way of testing this myself, but I may possibly have fixed the issue here. Can anyone see if the problem still exist with these changes?

@astrofrog

Copy link
Copy Markdown
Member Author

@AmrAS1 - I set up a script to test this many times and it seems like the issue happened 10% of the time:

Good: 043, Bad: 005, Failure rate:  10.4%

I tested out your branch and the result is similar:

Good: 026, Bad: 003, Failure rate:  10.3%

so I don't think the issue has been fixed.

@astrofrog

Copy link
Copy Markdown
Member Author

@AmrAS1 - in case this is useful, I noticed that it is not always the same assert that fails. Here is an example of one of the failures, with the tables printed out (this is with your branch):

______________________________________________________ test_fill_values ______________________________________________________

    def test_fill_values():
        """
        Make sure that the parameter fill_values works as intended. If fill_values
        is not specified, the default behavior should be to convert '' to 0.
        """
        text = """
    A, B, C
    , 2, nan
    a, -999, -3.4
    nan, 5, -9999
    8, nan, 7.6e12
    """
>       table = read_basic(text, delimiter=',')

astropy/io/ascii/tests/test_c_reader.py:440: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

table = '\nA, B, C\n, 2, nan\na, -999, -3.4\nnan, 5, -9999\n8, nan, 7.6e12\n', kwargs = {'delimiter': ','}

    def read_basic(table, **kwargs):
>       return _read(table, FastBasic, 'basic', **kwargs)

astropy/io/ascii/tests/test_c_reader.py:133: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

table = '\nA, B, C\n, 2, nan\na, -999, -3.4\nnan, 5, -9999\n8, nan, 7.6e12\n\n'
Reader = <class 'astropy.io.ascii.fastbasic.FastBasic'>, format = 'basic', fail_parallel = False, kwargs = {'delimiter': ','}
reader = <astropy.io.ascii.fastbasic.FastBasic object at 0x1042c0310>
t1 = <Table rows=4 names=('A','B','C')>
array([(2305843009213693952, 2.0, nan),
   ...an, 7600000000000.0)], 
      dtype=[('A', '<i8'), ('B', '<f8'), ('C', '<f8')])
t2 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, nan) ('a', -... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])

t3 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, nan) ('a', -... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])

t4 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, nan) ('a', -... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])

t5 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, nan) ('a', -... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])


    def _read(table, Reader, format, fail_parallel=False, **kwargs):
        # make sure we have a newline so table can't be misinterpreted as a filename
        table += '\n'
        reader = Reader(**kwargs)
        t1 = reader.read(table)
        t2 = reader.read(StringIO(table))
        t3 = reader.read(table.splitlines())
        t4 = ascii.read(table, format=format, guess=False, **kwargs)
        t5 = ascii.read(table, format=format, guess=False, fast_reader=False, **kwargs)

        try:
>           assert_table_equal(t1, t2)

astropy/io/ascii/tests/test_c_reader.py:55: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

t1 = <Table rows=4 names=('A','B','C')>
array([(2305843009213693952, 2.0, nan),
   ...an, 7600000000000.0)], 
      dtype=[('A', '<i8'), ('B', '<f8'), ('C', '<f8')])
t2 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, nan) ('a', -... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])


    def assert_table_equal(t1, t2):
        assert_equal(len(t1), len(t2))
        assert_equal(t1.colnames, t2.colnames)
        for name in t1.colnames:
            if len(t1) != 0:
>               assert_equal(t1[name].dtype.kind, t2[name].dtype.kind)

astropy/io/ascii/tests/test_c_reader.py:31: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = 'i', b = 'S'

    def assert_equal(a, b):
>       assert a == b
E       assert 'i' == 'S'
E         - i
E         + S

astropy/io/ascii/tests/common.py:41: AssertionError
------------------------------------------------------ Captured stdout -------------------------------------------------------
[('A', '<i8'), ('B', '<f8'), ('C', '<f8')]
         A             B       C   
-------------------- ------ -------
 2305843009213693952    2.0     nan
-2305834224835294703 -999.0    -3.4
          4364959746    5.0 -9999.0
     571734331819593    nan 7.6e+12
[('A', 'S3'), ('B', '<f8'), ('C', '<f8')]
 A    B       C   
--- ------ -------
 --    2.0     nan
  a -999.0    -3.4
nan    5.0 -9999.0
  8    nan 7.6e+12

Here is another failure:

__________________________________________________ test_quoted_empty_values __________________________________________________

    def test_quoted_empty_values():
        """
        Quoted empty values spanning multiple lines should be treated correctly.
        """
        text = 'a b c\n1 2 " \n "'
>       table = read_basic(text, fail_parallel=True)

astropy/io/ascii/tests/test_c_reader.py:684: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

table = 'a b c\n1 2 " \n "', kwargs = {'fail_parallel': True}

    def read_basic(table, **kwargs):
>       return _read(table, FastBasic, 'basic', **kwargs)

astropy/io/ascii/tests/test_c_reader.py:133: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

table = 'a b c\n1 2 " \n "\n', Reader = <class 'astropy.io.ascii.fastbasic.FastBasic'>, format = 'basic', fail_parallel = True
kwargs = {}, reader = <astropy.io.ascii.fastbasic.FastBasic object at 0x1063d7a50>
t1 = <Table rows=1 names=('a','b','c')>
masked_array(data = [(1, 2, --)],
         ...9999, 999999),
            dtype = [('a', '<i8'), ('b', '<i8'), ('c', '<i8')])

t2 = <Table rows=1 names=('a','b','c')>
masked_array(data = [(1, 2, --)],
         ...9999, 999999),
            dtype = [('a', '<i8'), ('b', '<i8'), ('c', '<i8')])

t3 = <Table rows=1 names=('a','b','c')>
masked_array(data = [(1, 2, --)],
         ...9999, 999999),
            dtype = [('a', '<i8'), ('b', '<i8'), ('c', '<i8')])

t4 = <Table rows=1 names=('a','b','c')>
array([(1, 2, -2305843009213693952)], 
      dtype=[('a', '<i8'), ('b', '<i8'), ('c', '<i8')])
t5 = <Table rows=1 names=('a','b','c')>
masked_array(data = [(1, 2, --)],
         ...9999, 999999),
            dtype = [('a', '<i8'), ('b', '<i8'), ('c', '<i8')])


    def _read(table, Reader, format, fail_parallel=False, **kwargs):
        # make sure we have a newline so table can't be misinterpreted as a filename
        table += '\n'
        reader = Reader(**kwargs)
        t1 = reader.read(table)
        t2 = reader.read(StringIO(table))
        t3 = reader.read(table.splitlines())
        t4 = ascii.read(table, format=format, guess=False, **kwargs)
        t5 = ascii.read(table, format=format, guess=False, fast_reader=False, **kwargs)

        try:
            assert_table_equal(t1, t2)
        except:
            print(t1.dtype)
            print(t1)
            print(t2.dtype)
            print(t2)
            raise

        try:
            assert_table_equal(t2, t3)
        except:
            print(t2.dtype)
            print(t2)
            print(t3.dtype)
            print(t3)
            raise

        try:
            assert_table_equal(t3, t4)
        except:
            print(t3.dtype)
            print(t3)
            print(t4.dtype)
            print(t4)
            raise

        try:
>           assert_table_equal(t4, t5)

astropy/io/ascii/tests/test_c_reader.py:82: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

t1 = <Table rows=1 names=('a','b','c')>
array([(1, 2, -2305843009213693952)], 
      dtype=[('a', '<i8'), ('b', '<i8'), ('c', '<i8')])
t2 = <Table rows=1 names=('a','b','c')>
masked_array(data = [(1, 2, --)],
         ...9999, 999999),
            dtype = [('a', '<i8'), ('b', '<i8'), ('c', '<i8')])


    def assert_table_equal(t1, t2):
        assert_equal(len(t1), len(t2))
        assert_equal(t1.colnames, t2.colnames)
        for name in t1.colnames:
            if len(t1) != 0:
                assert_equal(t1[name].dtype.kind, t2[name].dtype.kind)
            if not isinstance(t1[name], MaskedColumn):
                for i, el in enumerate(t1[name]):
                    try:
                        if not isinstance(el, six.string_types) and np.isnan(el):
                            assert_true(not isinstance(t2[name][i], six.string_types) and np.isnan(t2[name][i]))
                        elif isinstance(el, six.string_types):
                            assert_equal(el, t2[name][i])
                        else:
>                           assert_almost_equal(el, t2[name][i])

astropy/io/ascii/tests/test_c_reader.py:40: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = -2305843009213693952, b = masked

    def assert_almost_equal(a, b):
>       assert np.allclose(a, b)
E       assert <function allclose at 0x103b08aa0>(-2305843009213693952, masked)
E        +  where <function allclose at 0x103b08aa0> = <function allclose at 0x103b08aa0>
E        +    where <function allclose at 0x103b08aa0> = np.allclose

astropy/io/ascii/tests/common.py:45: AssertionError
------------------------------------------------------ Captured stdout -------------------------------------------------------
[('a', '<i8'), ('b', '<i8'), ('c', '<i8')]
 a   b           c          
--- --- --------------------
  1   2 -2305843009213693952
[('a', '<i8'), ('b', '<i8'), ('c', '<i8')]
 a   b   c 
--- --- ---
  1   2  --

and another

______________________________________________________ test_fill_values ______________________________________________________

    def test_fill_values():
        """
        Make sure that the parameter fill_values works as intended. If fill_values
        is not specified, the default behavior should be to convert '' to 0.
        """
        text = """
    A, B, C
    , 2, nan
    a, -999, -3.4
    nan, 5, -9999
    8, nan, 7.6e12
    """
        table = read_basic(text, delimiter=',')
        # The empty value in row A should become a masked '0'
        assert isinstance(table['A'], MaskedColumn)
        assert table['A'][0] is ma.masked
        # '0' rather than 0 because there is a string in the column
        assert_equal(table['A'].data.data[0], '0')
        assert table['A'][1] is not ma.masked

        table = read_basic(text, delimiter=',', fill_values=('-999', '0'))
        assert isinstance(table['B'], MaskedColumn)
        assert table['A'][0] is not ma.masked # empty value unaffected
        assert table['C'][2] is not ma.masked # -9999 is not an exact match
        assert table['B'][1] is ma.masked
        # Numeric because the rest of the column contains numeric data
        assert_equal(table['B'].data.data[1], 0.0)
        assert table['B'][0] is not ma.masked

        table = read_basic(text, delimiter=',', fill_values=[])
        # None of the columns should be masked
        for name in 'ABC':
            assert not isinstance(table[name], MaskedColumn)

        table = read_basic(text, delimiter=',', fill_values=[('', '0', 'A'),
>                                   ('nan', '999', 'A', 'C')])

astropy/io/ascii/tests/test_c_reader.py:463: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

table = '\nA, B, C\n, 2, nan\na, -999, -3.4\nnan, 5, -9999\n8, nan, 7.6e12\n'
kwargs = {'delimiter': ',', 'fill_values': [('', '0', 'A'), ('nan', '999', 'A', 'C')]}

    def read_basic(table, **kwargs):
>       return _read(table, FastBasic, 'basic', **kwargs)

astropy/io/ascii/tests/test_c_reader.py:133: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

table = '\nA, B, C\n, 2, nan\na, -999, -3.4\nnan, 5, -9999\n8, nan, 7.6e12\n\n'
Reader = <class 'astropy.io.ascii.fastbasic.FastBasic'>, format = 'basic', fail_parallel = False
kwargs = {'delimiter': ',', 'fill_values': [('', '0', 'A'), ('nan', '999', 'A', 'C')]}
reader = <astropy.io.ascii.fastbasic.FastBasic object at 0x1084ffb10>
t1 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, --) ('a', -9... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])

t2 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, --) ('a', -9... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])

t3 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, --) ('a', -9... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])

t4 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(5764607523034234880, ...1e+20, 1e+20),
            dtype = [('A', '<i8'), ('B', '<f8'), ('C', '<f8')])

t5 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, --) ('a', -9... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])


    def _read(table, Reader, format, fail_parallel=False, **kwargs):
        # make sure we have a newline so table can't be misinterpreted as a filename
        table += '\n'
        reader = Reader(**kwargs)
        t1 = reader.read(table)
        t2 = reader.read(StringIO(table))
        t3 = reader.read(table.splitlines())
        t4 = ascii.read(table, format=format, guess=False, **kwargs)
        t5 = ascii.read(table, format=format, guess=False, fast_reader=False, **kwargs)

        try:
            assert_table_equal(t1, t2)
        except:
            print(t1.dtype)
            print(t1)
            print(t2.dtype)
            print(t2)
            raise

        try:
            assert_table_equal(t2, t3)
        except:
            print(t2.dtype)
            print(t2)
            print(t3.dtype)
            print(t3)
            raise

        try:
>           assert_table_equal(t3, t4)

astropy/io/ascii/tests/test_c_reader.py:73: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

t1 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(--, 2.0, --) ('a', -9... 1e+20, 1e+20),
            dtype = [('A', 'S3'), ('B', '<f8'), ('C', '<f8')])

t2 = <Table rows=4 names=('A','B','C')>
masked_array(data = [(5764607523034234880, ...1e+20, 1e+20),
            dtype = [('A', '<i8'), ('B', '<f8'), ('C', '<f8')])


    def assert_table_equal(t1, t2):
        assert_equal(len(t1), len(t2))
        assert_equal(t1.colnames, t2.colnames)
        for name in t1.colnames:
            if len(t1) != 0:
>               assert_equal(t1[name].dtype.kind, t2[name].dtype.kind)

astropy/io/ascii/tests/test_c_reader.py:31: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = 'S', b = 'i'

    def assert_equal(a, b):
>       assert a == b
E       assert 'S' == 'i'
E         - S
E         + i

astropy/io/ascii/tests/common.py:41: AssertionError
------------------------------------------------------ Captured stdout -------------------------------------------------------
[('A', 'S3'), ('B', '<f8'), ('C', '<f8')]
 A    B       C   
--- ------ -------
 --    2.0      --
  a -999.0    -3.4
 --    5.0 -9999.0
  8    nan 7.6e+12
[('A', '<i8'), ('B', '<f8'), ('C', '<f8')]
         A            B       C   
------------------- ------ -------
5764607523034234880    2.0      --
1152930289512690672 -999.0    -3.4
         4398514178    5.0 -9999.0
    562954351945112    nan 7.6e+12

@mdmueller

Copy link
Copy Markdown
Contributor

@astrofrog - Thanks for the output -- I had been assuming it had something to do with the include/exclude names scheme, which doesn't seem to be the case. Looks like there's a problem with empty values that somehow screws up the rest of the column...I'll see if I can figure out what's up.

@embray embray added Bug Affects-dev PRs and issues that do not impact an existing Astropy release labels Sep 29, 2014
@mdmueller

Copy link
Copy Markdown
Contributor

@astrofrog - Sorry I haven't been able to look at this for a while. I managed to get hold of a Mac to do a bit of testing, and the fix in this branch worked for me. Can you test this out and see if the test failures persist?

@astrofrog

Copy link
Copy Markdown
Member Author

@AmrAS1 - unfortunately it looks like the issue is still there. I wrote this script to repeat the test many times:

https://gist.github.com/astrofrog/d7be9e4b6bfc474d5a18

I seem to get a failure between 5 and 10% of the time. I'm wondering whether it has to do with optimization.

@astrofrog

Copy link
Copy Markdown
Member Author

@AmrAS1 - you can also instead use my repeat-option branch (https://github.com/astrofrog/astropy/tree/repeat-option), make sure you use build_ext --inplace, and then I can reproduce the failures although less frequently somehow:

$ py.test --repeat=1000 -k test_fill_include_exclude_names astropy/io/ascii/tests/test_c_reader.py
======================================================================= test session starts ========================================================================
platform darwin -- Python 3.4.1 -- py-1.4.23 -- pytest-2.6.1

Running tests with Astropy version 1.0.dev10080.
Running tests in astropy/io/ascii/tests/test_c_reader.py.

Platform: Darwin-12.5.0-x86_64-i386-64bit

Executable: /opt/local/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4

Full Python Version: 
3.4.1 (default, May 21 2014, 21:17:51) 
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))]

encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
byteorder: little
float info: dig: 15, mant_dig: 15

Numpy: 1.10.0.dev-a32625e
Scipy: 0.14.0
Matplotlib: 1.4.0
h5py: 2.3.1

collected 66000 items 

astropy/io/ascii/tests/test_c_reader.py ..................................................................................................................................................................................................................................................................................................................................................................................................................................................F............................................................................................................................................................................................................................................................................F................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

============================================================================= FAILURES =============================================================================
____________________________________________________________ test_fill_include_exclude_names[217-True] _____________________________________________________________

parallel = True

    @pytest.mark.parametrize("parallel", [True, False])
    def test_fill_include_exclude_names(parallel):
        """
        fill_include_names and fill_exclude_names should filter missing/empty value handling
        in the same way that include_names and exclude_names filter output columns.
        """
        text = """
    A, B, C
    , 1, 2
    3, , 4
    5, 5,
    """
        table = read_csv(text, fill_include_names=['A', 'B'], parallel=parallel)
        assert table['A'][0] is ma.masked
        assert table['B'][1] is ma.masked
        assert table['C'][2] is not ma.masked # C not in fill_include_names

        table = read_csv(text, fill_exclude_names=['A', 'B'], parallel=parallel)
        assert table['C'][2] is ma.masked
        assert table['A'][0] is not ma.masked
        assert table['B'][1] is not ma.masked # A and B excluded from fill handling

>       table = read_csv(text, fill_include_names=['A', 'B'], fill_exclude_names=['B'], parallel=parallel)

astropy/io/ascii/tests/test_c_reader.py:463: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astropy/io/ascii/tests/test_c_reader.py:84: in read_csv
    return _read(table, FastCsv, 'csv', **kwargs)
astropy/io/ascii/tests/test_c_reader.py:77: in _read
    assert_table_equal(t1, t8)
astropy/io/ascii/tests/test_c_reader.py:31: in assert_table_equal
    assert_equal(t1[name].dtype.kind, t2[name].dtype.kind)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = 'i', b = 'U'

    def assert_equal(a, b):
>       assert a == b
E       assert 'i' == 'U'
E         - i
E         + U

astropy/io/ascii/tests/common.py:41: AssertionError
____________________________________________________________ test_fill_include_exclude_names[351-False] ____________________________________________________________

parallel = False

    @pytest.mark.parametrize("parallel", [True, False])
    def test_fill_include_exclude_names(parallel):
        """
        fill_include_names and fill_exclude_names should filter missing/empty value handling
        in the same way that include_names and exclude_names filter output columns.
        """
        text = """
    A, B, C
    , 1, 2
    3, , 4
    5, 5,
    """
>       table = read_csv(text, fill_include_names=['A', 'B'], parallel=parallel)

astropy/io/ascii/tests/test_c_reader.py:453: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astropy/io/ascii/tests/test_c_reader.py:84: in read_csv
    return _read(table, FastCsv, 'csv', **kwargs)
astropy/io/ascii/tests/test_c_reader.py:53: in _read
    assert_table_equal(t1, t2)
astropy/io/ascii/tests/test_c_reader.py:31: in assert_table_equal
    assert_equal(t1[name].dtype.kind, t2[name].dtype.kind)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

a = 'U', b = 'i'

    def assert_equal(a, b):
>       assert a == b
E       assert 'U' == 'i'
E         - U
E         + i

astropy/io/ascii/tests/common.py:41: AssertionError
================================================== 64000 tests deselected by '-ktest_fill_include_exclude_names' ===================================================
==================================================== 2 failed, 1998 passed, 64000 deselected in 341.92 seconds =====================================================

(I had to rebase your branch on master to avoid the 'too many files' error)

@mdmueller

Copy link
Copy Markdown
Contributor

@astrofrog - I think I might have a solution with the latest commit in this branch; I repeated tests 100 times and didn't get an error. Can you test this out?

Sorry it's taken so long for me to look more into this--I've been busier than I anticipated. By the way, I changed my Github username (previously amras1).

@astrofrog

Copy link
Copy Markdown
Member Author

@mdmueller - works for me! I've attached the branch to this issue. Thanks!

@astrofrog astrofrog added this to the v1.0.0 milestone Nov 2, 2014
@astrofrog

Copy link
Copy Markdown
Member Author

@mdmueller - just to check, do you consider this ready to merge?

@mdmueller

Copy link
Copy Markdown
Contributor

Yes, this is good from my perspective.

@astrofrog

Copy link
Copy Markdown
Member Author

Ok, thanks! Merging :)

astrofrog added a commit that referenced this pull request Nov 3, 2014
Sporadic test failure with fast io.ascii reader
@astrofrog
astrofrog merged commit 0610e28 into astropy:master Nov 3, 2014
@mdmueller
mdmueller deleted the fix-mac-issue branch November 3, 2014 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Affects-dev PRs and issues that do not impact an existing Astropy release Bug io.ascii

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants