Repository: pandas-dev/pandas

Issue:
Reading zipped utf-16 file: AttributeError: 'UTF8Recoder' object has no attribute 'seek' 
#### Code Sample, a copy-pastable example if possible

```python
df = pd.read_table('myfile.zip', 
                   compression='zip',
                   encoding='utf-16')
```
#### Problem description
      Traceback (most recent call last):

     File "<ipython-input-4-6daea174e70a>", line 3, in <module>
      encoding='utf-16')

    File "/Users/Nick/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 705, in parser_f
      return _read(filepath_or_buffer, kwds)

    File "/Users/Nick/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 445, in _read
      parser = TextFileReader(filepath_or_buffer, **kwds)

    File "/Users/Nick/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 814, in __init__
      self._make_engine(self.engine)

    File "/Users/Nick/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 1045, in _make_engine
      self._engine = CParserWrapper(self.f, **self.options)

    File "/Users/Nick/anaconda/lib/python3.5/site-packages/pandas/io/parsers.py", line 1684, in __init__
      self._reader = parsers.TextReader(src, **kwds)

    File "pandas/_libs/parsers.pyx", line 391, in pandas._libs.parsers.TextReader.__cinit__

    File "pandas/_libs/parsers.pyx", line 664, in pandas._libs.parsers.TextReader._setup_parser_source

    File "/Users/Nick/anaconda/lib/python3.5/zipfile.py", line 1026, in __init__
      self._RealGetContents()

    File "/Users/Nick/anaconda/lib/python3.5/zipfile.py", line 1090, in _RealGetContents
      endrec = _EndRecData(fp)

    File "/Users/Nick/anaconda/lib/python3.5/zipfile.py", line 241, in _EndRecData
      fpin.seek(0, 2)

     AttributeError: 'UTF8Recoder' object has no attribute 'seek'

#### Expected Output

A table!

#### Output of ``pd.show_versions()``

<details>

  pd.show_versions()

  INSTALLED VERSIONS
  ------------------
  commit: None
  python: 3.5.3.final.0
  python-bits: 64
  OS: Darwin
  OS-release: 16.7.0
  machine: x86_64
  processor: i386
  byteorder: little
  LC_ALL: None
  LANG: en_US.UTF-8
  LOCALE: en_US.UTF-8

  pandas: 0.21.0
  pytest: 3.0.7
  pip: 9.0.1
  setuptools: 33.1.1.post20170320
  Cython: 0.25.2
  numpy: 1.11.3
  scipy: 0.19.0
  pyarrow: None
  xarray: None
  IPython: 5.3.0
  sphinx: 1.5.4
  patsy: 0.4.1
  dateutil: 2.6.1
  pytz: 2016.10
  blosc: None
  bottleneck: 1.2.0
  tables: 3.3.0
  numexpr: 2.6.2
  feather: None
  matplotlib: 1.5.1
  openpyxl: 2.4.5
  xlrd: 1.0.0
  xlwt: 1.2.0
  xlsxwriter: 0.9.6
  lxml: 3.7.3
  bs4: 4.5.3
  html5lib: 0.999
  sqlalchemy: 1.1.5
  pymysql: None
  psycopg2: 2.6.2 (dt dec pq3 ext lo64)
  jinja2: 2.9.5
  s3fs: 0.0.9
  fastparquet: None
  pandas_gbq: None
  pandas_datareader: None
</details>



Discussion:
Hmmm...that looks kind of odd.  Mind sharing the ZIP file for us to reproduce?
@gfyoung sorry for delay -- couldn't upload original file, but here's what seems to be a minimal working example

[sample.zip](https://github.com/pandas-dev/pandas/files/1439381/sample.zip)

Yep, can reproduce this error.  Investigation and PR patch is welcome!

Resolving patch:
diff --git a/pandas/io/parsers.py b/pandas/io/parsers.py
--- a/pandas/io/parsers.py
+++ b/pandas/io/parsers.py
@@ -1671,7 +1671,9 @@ def __init__(self, src, **kwds):
 
         ParserBase.__init__(self, kwds)
 
-        if 'utf-16' in (kwds.get('encoding') or ''):
+        if (kwds.get('compression') is None
+           and 'utf-16' in (kwds.get('encoding') or '')):
+            # if source is utf-16 plain text, convert source to utf-8
             if isinstance(src, compat.string_types):
                 src = open(src, 'rb')
                 self.handles.append(src)


Test patch:
diff --git a/pandas/tests/io/parser/compression.py b/pandas/tests/io/parser/compression.py
--- a/pandas/tests/io/parser/compression.py
+++ b/pandas/tests/io/parser/compression.py
@@ -7,6 +7,7 @@
 
 import pytest
 
+import pandas as pd
 import pandas.util.testing as tm
 
 
@@ -157,6 +158,19 @@ def test_read_csv_infer_compression(self):
 
         inputs[3].close()
 
+    def test_read_csv_compressed_utf16_example(self):
+        # GH18071
+        path = tm.get_data_path('utf16_ex_small.zip')
+
+        result = self.read_csv(path, encoding='utf-16',
+                               compression='zip', sep='\t')
+        expected = pd.DataFrame({
+            u'Country': [u'Venezuela', u'Venezuela'],
+            u'Twitter': [u'Hugo Chávez Frías', u'Henrique Capriles R.']
+        })
+
+        tm.assert_frame_equal(result, expected)
+
     def test_invalid_compression(self):
         msg = 'Unrecognized compression type: sfark'
         with tm.assert_raises_regex(ValueError, msg):
diff --git a/pandas/tests/io/parser/data/utf16_ex_small.zip b/pandas/tests/io/parser/data/utf16_ex_small.zip
new file mode 100644
Binary files /dev/null and b/pandas/tests/io/parser/data/utf16_ex_small.zip differ