title: pandas.read_sas() for reading SAS .xpt file does not work with file stored in Google Cloud Storage (GCS)
body: <p>I am attempting to read an .XPT file into a Pandas DataFrame. This works if the file is local but not if the file is stored in GCS.</p>
  
  <p>I uploaded the sample data to GCS using:</p>
  
  <pre class="lang-sh prettyprint-override"><code>!curl -L https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/DEMO_J.XPT | gsutil cp - gs://my-bucket/sas_sample/Nchs/Nhanes/2017-2018/DEMO_J.XPT
  </code></pre>
  
  <p>I also downloaded the file locally using:</p>
  
  <pre class="lang-sh prettyprint-override"><code>mkdir data
  !curl https://wwwn.cdc.gov/Nchs/Nhanes/2017-2018/DEMO_J.XPT -o data/DEMO_J.XPT
  </code></pre>
  
  <p>I have tried the following with GCSbut neither of them work:</p>
  
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import gcsfs
  
  fs = gcsfs.GCSFileSystem(project='my-project')
  with fs.open('my-bucket/sas_sample/Nchs/Nhanes/2017-2018/DEMO_J.XPT') as f:
      df = pd.read_sas(f,format='xport')
  
  </code></pre>
  
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  
  filepath = 'gs://my-bucket/sas_sample/Nchs/Nhanes/2017-2018/DEMO_J.XPT'
  df = pd.read_sas(filepath, format='xport', encoding='utf-8')
  df.head(10)
  </code></pre>
  
  <p>They both return the following error:</p>
  
  <pre><code>/opt/conda/anaconda/lib/python3.7/site-packages/pandas/io/sas/sas_xport.py in __init__(self, filepath_or_buffer, index, encoding, chunksize)
      278             contents = filepath_or_buffer.read()
      279             try:
  --&gt; 280                 contents = contents.encode(self._encoding)
      281             except UnicodeEncodeError:
      282                 pass
  
  AttributeError: 'bytes' object has no attribute 'encode'
  </code></pre>
  
  <p>Also now tried with TensorFlow which does not work:</p>
  
  <pre><code>from tensorflow.python.lib.io import file_io
  import pandas as pd
  
  filepath = 'gs://my-bucket/sas_sample/Nchs/Nhanes/2017-2018/DEMO_J.XPT'
  
  with file_io.FileIO(filepath, 'r') as f:
  
      # ISO-8859-1
      # utf-8
      # utf-16
      # latin-1
      df = pd.read_sas(f, format='xport', encoding='utf-8')
  
  df.head(5)
  
  </code></pre>
  
  <p>Returns error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  UnicodeDecodeError                        Traceback (most recent call last)
  &lt;ipython-input-60-fb02f0706587&gt; in &lt;module&gt;
       10     # utf-16
       11     # latin-1
  ---&gt; 12     df = pd.read_sas(f, format='xport', encoding='utf-8')
       13 
       14 df.head(5)
  
  /opt/conda/anaconda/lib/python3.7/site-packages/pandas/io/sas/sasreader.py in read_sas(filepath_or_buffer, format, index, encoding, chunksize, iterator)
       68 
       69         reader = XportReader(
  ---&gt; 70             filepath_or_buffer, index=index, encoding=encoding, chunksize=chunksize
       71         )
       72     elif format.lower() == "sas7bdat":
  
  /opt/conda/anaconda/lib/python3.7/site-packages/pandas/io/sas/sas_xport.py in __init__(self, filepath_or_buffer, index, encoding, chunksize)
      276         else:
      277             # Copy to BytesIO, and ensure no encoding
  --&gt; 278             contents = filepath_or_buffer.read()
      279             try:
      280                 contents = contents.encode(self._encoding)
  
  /opt/conda/anaconda/lib/python3.7/site-packages/tensorflow_core/python/lib/io/file_io.py in read(self, n)
      126       length = n
      127     return self._prepare_value(
  --&gt; 128         pywrap_tensorflow.ReadFromStream(self._read_buf, length))
      129 
      130   @deprecation.deprecated_args(
  
  /opt/conda/anaconda/lib/python3.7/site-packages/tensorflow_core/python/lib/io/file_io.py in _prepare_value(self, val)
       96       return compat.as_bytes(val)
       97     else:
  ---&gt; 98       return compat.as_str_any(val)
       99 
      100   def size(self):
  
  /opt/conda/anaconda/lib/python3.7/site-packages/tensorflow_core/python/util/compat.py in as_str_any(value)
      137   """
      138   if isinstance(value, bytes):
  --&gt; 139     return as_str(value)
      140   else:
      141     return str(value)
  
  /opt/conda/anaconda/lib/python3.7/site-packages/tensorflow_core/python/util/compat.py in as_text(bytes_or_text, encoding)
      107     return bytes_or_text
      108   elif isinstance(bytes_or_text, bytes):
  --&gt; 109     return bytes_or_text.decode(encoding)
      110   else:
      111     raise TypeError('Expected binary or unicode string, got %r' % bytes_or_text)
  
  UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 2967: invalid start byte
  </code></pre>
  
  <p>But the following works correctly when the file is local:</p>
  
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  
  filepath = 'data/DEMO_J.XPT'
  df = pd.read_sas(filepath, format='xport', encoding='utf-8')
  df.head(10)
  </code></pre>