Repository: pandas-dev/pandas

Issue:
same .tsv file, get different data-frame structure using engine 'python' and 'c'
In my Mac, I have a Tab-Separated values file with encoding UTF-8, and the version of pandas is 
0.24.2.
[74872_zh_CN_UI.txt](https://github.com/pandas-dev/pandas/files/3227255/74872_zh_CN_UI.txt)

when I use read_csv function with engine 'python' like this:
`b = pd.read_csv("/Users/GHIBLI/Documents/vmware-L10n/bert/zh_CN/74872_zh_CN_UI.tsv",
                engine="python", delimiter="\t")`
` print(b.shape)`
I got (8, 1)

if with default engine:
`b = pd.read_csv("/Users/GHIBLI/Documents/vmware-L10n/bert/zh_CN/74872_zh_CN_UI.tsv",
                delimiter="\t")`
` print(b.shape)`
I got (8,22)

In contrast to 'C' engine, this 'python' engine seems that is not as simple as  just 'feature-complete' I think.




Discussion:
I cannot reproduce using pandas 0.24.2 on either Ubuntu or Windows -- both show the shape as (8, 22) using both engines. It could be a Mac-specific issue, though it would be odd that the Python-engine implementation would behave differently based on the OS.
I can reproduce this on master. If you would like to take a deeper look and see what's going on would certainly appreciate it!
@WillAyd Are you using a Mac? I can't reproduce on master using Windows/python 3.7.3 (I suppose perhaps this could also be a python version difference, rather than an OS difference)

```python
In [1]: import pandas as pd

In [2]: pd.__version__
Out[2]: '0.25.0.dev0+615.g998a0deea'

In [3]: pd.read_csv('74872_zh_CN_UI.txt', delimiter='\t', engine='python').shape
Out[3]: (8, 22)
```
Yes macOS on master

Sent from my iPhone

> On May 28, 2019, at 8:37 AM, David Krych <notifications@github.com> wrote:
> 
> @WillAyd Are you using a Mac? I can't reproduce on master using Windows/python 3.7.3 (I suppose perhaps this could also be a python version difference, rather than an OS difference)
> 
> In [1]: import pandas as pd
> 
> In [2]: pd.__version__
> Out[2]: '0.25.0.dev0+615.g998a0deea'
> 
> In [3]: pd.read_csv('74872_zh_CN_UI.txt', delimiter='\t', engine='python').shape
> Out[3]: (8, 22)
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub, or mute the thread.

I was able to play on linux 19.04 Python 3.7 Pandas 0.24.2
Good afternoon, I found where in what a mistake. But have not yet figured out how best to fix it. Do you mind if I take this task?

Resolving patch:
diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py
--- a/pandas/io/parsers.py
+++ b/pandas/io/parsers.py
@@ -2755,23 +2755,24 @@ def _check_for_bom(self, first_row):
         if first_elt != _BOM:
             return first_row
 
-        first_row = first_row[0]
+        first_row_bom = first_row[0]
 
-        if len(first_row) > 1 and first_row[1] == self.quotechar:
+        if len(first_row_bom) > 1 and first_row_bom[1] == self.quotechar:
             start = 2
-            quote = first_row[1]
-            end = first_row[2:].index(quote) + 2
+            quote = first_row_bom[1]
+            end = first_row_bom[2:].index(quote) + 2
 
             # Extract the data between the quotation marks
-            new_row = first_row[start:end]
+            new_row = first_row_bom[start:end]
 
             # Extract any remaining data after the second
             # quotation mark.
-            if len(first_row) > end + 1:
-                new_row += first_row[end + 1:]
-            return [new_row]
-        elif len(first_row) > 1:
-            return [first_row[1:]]
+            if len(first_row_bom) > end + 1:
+                new_row += first_row_bom[end + 1:]
+            return [new_row] + first_row[1:]
+
+        elif len(first_row_bom) > 1:
+            return [first_row_bom[1:]]
         else:
             # First row is just the BOM, so we
             # return an empty string.


Test patch:
diff --git a/pandas/tests/io/parser/test_common.py b/pandas/tests/io/parser/test_common.py
--- a/pandas/tests/io/parser/test_common.py
+++ b/pandas/tests/io/parser/test_common.py
@@ -1927,3 +1927,13 @@ def test_read_table_deprecated(all_parsers):
                                     check_stacklevel=False):
         result = parser.read_table(StringIO(data))
         tm.assert_frame_equal(result, expected)
+
+
+def test_first_row_bom(all_parsers):
+    # see gh-26545
+    parser = all_parsers
+    data = '''\ufeff"Head1"	"Head2"	"Head3"'''
+
+    result = parser.read_csv(StringIO(data), delimiter='\t')
+    expected = DataFrame(columns=["Head1", "Head2", "Head3"])
+    tm.assert_frame_equal(result, expected)