Repository: scipy/scipy

Issue:
scipy.io.mmread generated an error "TypeError: startswith first arg must be str or a tuple of str, not bytes"
scipy.io.mmread generated an error "TypeError: startswith first arg must be str or a tuple of str, not bytes"

For the downloaded matrix-market file; young1c.mtx, from https://math nist.gov/MatrixMarket/data/Harwell-Boeing/acoust/young1c.html,    scipy.io. generated an error. I am working on Windows 10.

What I experienced was:

```
C:\home\textd\Matrices>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> fn = open("young1c.mtx","r")
>>> import scipy.io
>>> x = scipy.io.mmread(fn)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python37\lib\site-packages\scipy\io\mmio.py", line 75, in mmread
    return MMFile().read(source)
  File "C:\Python37\lib\site-packages\scipy\io\mmio.py", line 420, in read
    self._parse_header(stream)
  File "C:\Python37\lib\site-packages\scipy\io\mmio.py", line 484, in _parse_header
    self.__class__.info(stream)
  File "C:\Python37\lib\site-packages\scipy\io\mmio.py", line 246, in info
    while line.startswith(b'%'):
TypeError: startswith first arg must be str or a tuple of str, not bytes
```

Is there anything wrong with me?

regards,





Discussion:

Resolving patch:
diff --git a/scipy/io/mmio.py b/scipy/io/mmio.py
--- a/scipy/io/mmio.py
+++ b/scipy/io/mmio.py
@@ -242,7 +242,8 @@ def info(self, source):
                 format = self.FORMAT_COORDINATE
 
             # skip comments
-            while line.startswith(b'%'):
+            # line.startswith('%')
+            while line and line[0] in ['%', 37]:
                 line = stream.readline()
 
             # skip empty lines
@@ -515,7 +516,8 @@ def _parse_body(self, stream):
                     i += 1
             while line:
                 line = stream.readline()
-                if not line or line.startswith(b'%') or not line.strip():
+                # line.startswith('%')
+                if not line or line[0] in ['%', 37] or not line.strip():
                     continue
                 if is_integer:
                     aij = int(line)
@@ -560,7 +562,8 @@ def _parse_body(self, stream):
             k = 0
             while line:
                 line = stream.readline()
-                if not line or line.startswith(b'%') or not line.strip():
+                # line.startswith('%')
+                if not line or line[0] in ['%', 37] or not line.strip():
                     continue
                 l = line.split()
                 i, j = map(int, l[:2])
@@ -607,7 +610,8 @@ def _parse_body(self, stream):
 
             entry_number = 0
             for line in stream:
-                if not line or line.startswith(b'%') or not line.strip():
+                # line.startswith('%')
+                if not line or line[0] in ['%', 37] or not line.strip():
                     continue
 
                 if entry_number+1 > entries:


Test patch:
diff --git a/scipy/io/tests/test_mmio.py b/scipy/io/tests/test_mmio.py
--- a/scipy/io/tests/test_mmio.py
+++ b/scipy/io/tests/test_mmio.py
@@ -2,6 +2,7 @@
 
 from tempfile import mkdtemp, mktemp
 import os
+import io
 import shutil
 
 import numpy as np
@@ -698,3 +699,9 @@ def test_precision(self):
                 assert_array_equal(A.col, [n-1])
                 assert_array_almost_equal(A.data,
                     [float('%%.%dg' % precision % value)])
+
+
+def test_gh11389():
+    mmread(io.StringIO("%%MatrixMarket matrix coordinate complex symmetric\n"
+                       " 1 1 1\n"
+                       "1 1 -2.1846000000000e+02  0.0000000000000e+00"))