Repository: astropy/astropy

Issue:
FixedWidthNoHeader table not splitting on first data line
Is the following routine giving correct behavior?  Output:

``` 
A   B   C 
--- --- ---
  1   2   3
  4   5   6
 A   B   C 
--- --- ---
1 2   3  --
4 5   6  --
```
I thought the `fixed_width_no_header` reader was supposed to split the first data line, but it appears to be splitting the first line instead.

I'm using python 3.6.5, numpy 1.14.5, astropy 3.1.1.

In case this is a bug, I wonder about io/ascii/core.py line 1163, `self.header.get_cols(self.lines)`

```
def testsplit():
    kwds = dict(data_start=1, data_end=3,
                     delimiter=' ', names=['A','B','C'], 
                     format='fixed_width_no_header')
    foo = """x y z
1 2 3
4 5 6
"""   
    print(ascii.read(foo, **kwds))

    foo = """AAA y z
1 2 3
4 5 6
"""
    print(ascii.read(foo, **kwds))
```

Discussion:
bsipocz: @fardal - could you please add a test? your example from the issue would be perfect. And also a changelog entry under the section 2.0.13.
codecov[bot]: # [Codecov](https://codecov.io/gh/astropy/astropy/pull/8511?src=pr&el=h1) Report
> Merging [#8511](https://codecov.io/gh/astropy/astropy/pull/8511?src=pr&el=desc) into [master](https://codecov.io/gh/astropy/astropy/commit/642a7768b4ec2e3ab9fd9acdf53632a3c7eca372?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/astropy/astropy/pull/8511/graphs/tree.svg?width=650&token=eEhbJxwU0j&height=150&src=pr)](https://codecov.io/gh/astropy/astropy/pull/8511?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #8511   +/-   ##
=======================================
  Coverage   86.81%   86.81%           
=======================================
  Files         386      386           
  Lines       58166    58166           
  Branches     1060     1060           
=======================================
  Hits        50495    50495           
  Misses       7056     7056           
  Partials      615      615
```


| [Impacted Files](https://codecov.io/gh/astropy/astropy/pull/8511?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [astropy/io/ascii/fixedwidth.py](https://codecov.io/gh/astropy/astropy/pull/8511/diff?src=pr&el=tree#diff-YXN0cm9weS9pby9hc2NpaS9maXhlZHdpZHRoLnB5) | `96.75% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/astropy/astropy/pull/8511?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/astropy/astropy/pull/8511?src=pr&el=footer). Last update [642a776...26e5bac](https://codecov.io/gh/astropy/astropy/pull/8511?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

fardal: 
I entered a line in the changelog, but the astropy-bot:changelog still complains.  Not sure what's wrong.  In the process added and tried to delete an extra commit.

I don't know anything about the astropy test framework. I'd require some help to make it work.  Here is a nose-style test, which fails for the master branch and passes for the pull request branch.

Again: someone who understands the overall table code should check the bug fix makes sense.

```
from astropy.io import ascii
def test_colsplit():
    from astropy.utils.diff import report_diff_values
    kwds = dict(data_start=1, data_end=3,
                     delimiter=' ', names=['A','B','C'], 
                     format='fixed_width_no_header')
    foo = """x y z
1 2 3
4 5 6
"""   
    tab1 = ascii.read(foo, **kwds)

    foo = """AAA y z
1 2 3
4 5 6
"""
    tab2 = ascii.read(foo, **kwds)
    identical = report_diff_values(tab1, tab2)
    assert identical    
```

astropy-bot[bot]:  Hi humans :wave: - this pull request hasn't had any new commits for approximately 5 months. **I plan to close this in a month if the pull request doesn't have any new commits by then.**

In lieu of a stalled pull request, please consider closing this and open an issue instead if a reminder is needed to revisit in the future. Maintainers may also choose to add `keep-open` label to keep this PR open but it is discouraged unless absolutely necessary.

If this PR still needs to be reviewed, as an author, you can rebase it to reset the clock.

*If you believe I commented on this pull request incorrectly, please report this [here](https://github.com/OpenAstronomy/baldrick/issues).*
astropy-bot[bot]:  I'm going to close this pull request as per my previous message. If you think what is being added/fixed here is still important, please remember to open an issue to keep track of it. Thanks!

*If this is the first time I am commenting on this issue, or if you believe I closed this issue incorrectly, please report this [here](https://github.com/OpenAstronomy/baldrick/issues).*

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 3bf050a8f5..73d1d59f4d 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -2582,6 +2582,9 @@ astropy.stats
 astropy.table
 ^^^^^^^^^^^^^
 
+- Fix ``FixedWidthNoHeader`` to pay attention to ``data_start`` keyword when
+  finding first data line to split columns [#8485, #8511]
+
 astropy.tests
 ^^^^^^^^^^^^^
 
diff --git a/astropy/io/ascii/fixedwidth.py b/astropy/io/ascii/fixedwidth.py
index 76c399dbb6..979b505894 100644
--- a/astropy/io/ascii/fixedwidth.py
+++ b/astropy/io/ascii/fixedwidth.py
@@ -103,7 +103,11 @@ class FixedWidthHeader(basic.BasicHeader):
         if start_line is None:
             if position_line is not None:
                 raise ValueError("Cannot set position_line without also setting header_start")
-            data_lines = self.data.process_lines(lines)
+
+            # data.data_lines attribute already set via self.data.get_data_lines(lines)
+            # in BaseReader.read().  This includes slicing for data_start / data_end.
+            data_lines = self.data.data_lines
+
             if not data_lines:
                 raise InconsistentTableError(
                     'No data lines found so cannot autogenerate column names')


Test patch:
diff --git a/astropy/io/ascii/tests/test_fixedwidth.py b/astropy/io/ascii/tests/test_fixedwidth.py
index a9ce9ebb07..6f33cbff8d 100644
--- a/astropy/io/ascii/tests/test_fixedwidth.py
+++ b/astropy/io/ascii/tests/test_fixedwidth.py
@@ -3,6 +3,7 @@
 
 from io import StringIO
 
+import numpy as np
 import pytest
 
 from astropy.io import ascii
@@ -478,3 +479,21 @@ def test_write_twoline_no_bookend():
 | 1.2|  "hello"|   1|   a|
 | 2.4|'s worlds|   2|   2|
 """)
+
+
+def test_fixedwidthnoheader_splitting():
+    """Test fix in #8511 where data_start is being ignored"""
+    tbl = """\
+AAA y z
+1 2 3
+4 5 6
+7 8 9
+"""
+    names = ['a', 'b', 'c']
+    dat = ascii.read(tbl, data_start=1, data_end=3,
+                     delimiter=' ', names=names,
+                     format='fixed_width_no_header')
+    assert dat.colnames == names
+    assert np.all(dat['a'] == [1, 4])
+    assert np.all(dat['b'] == [2, 5])
+    assert np.all(dat['c'] == [3, 6])