Repository: scipy/scipy

Issue:
SyntaxError: Non-ASCII character '\xe2' in file scipy/stats/_continuous_distns.py on line 3346, but no encoding declared
I get syntax errors due to source code encodings when importing scipy 1.2.0. The error only seems to occur if `pyc` files are missing.

The issue originates from https://github.com/scipy/scipy/blob/v1.2.0/scipy/stats/_continuous_distns.py#L3345. The dash/hyphen used there isn't a regular dash/hyphen, but instead the line reads as `'    pp. 1\xe2\x80\x9313, 1997.\n'`

### Reproducing code example:

```Dockerfile
FROM python:2.7

RUN pip install --no-cache-dir scipy

# Without the following line, I can't reproduce the problem.
RUN find /usr/local/lib/python2.7/site-packages/scipy/ -name '*.pyc' -delete

RUN python -c "import scipy.stats"
```

### Error message:

```
Step 1/4 : FROM python:2.7
 ---> f67e752245d6
Step 2/4 : RUN pip install --no-cache-dir scipy
 ---> Using cache
 ---> e8adb88b0f15
Step 3/4 : RUN find /usr/local/lib/python2.7/site-packages/scipy/ -name '*.pyc' -delete
 ---> Running in 6e46e320f24d
Removing intermediate container 6e46e320f24d
 ---> ed5be7afd25a
Step 4/4 : RUN python -c "import scipy.stats"
 ---> Running in 8c8ea36e3284
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/scipy/stats/__init__.py", line 367, in <module>
    from .stats import *
  File "/usr/local/lib/python2.7/site-packages/scipy/stats/stats.py", line 173, in <module>
    from . import distributions
  File "/usr/local/lib/python2.7/site-packages/scipy/stats/distributions.py", line 13, in <module>
    from . import _continuous_distns
  File "/usr/local/lib/python2.7/site-packages/scipy/stats/_continuous_distns.py", line 3345
SyntaxError: Non-ASCII character '\xe2' in file /usr/local/lib/python2.7/site-packages/scipy/stats/_continuous_distns.py on line 3346, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
```

### Scipy/Numpy/Python version information:
```
import sys, scipy, numpy; print(scipy.__version__, numpy.__version__, sys.version_info)
('1.2.0', '1.15.4', sys.version_info(major=2, minor=7, micro=15, releaselevel='final', serial=0))
```


Discussion:
Grr, this is the second time this happened. We really need a structural fix to our CI to catch this.

Thanks for the report @dimrozakis.

@tylerjereddy guess we'll need a 1.2.1 (after the CI fix) .... :(
What would be the test for this?
Use `grep` or some other `bash` util to get a list of py files with non-ascii chars; get a list of files with `# -*- coding: utf-8 -*-` at the top; take the first list minus the second and you have the problematic ones? This or something similar should be `bash`-able on one of the Travis builds. I can take a stab at it if nobody sees a cleaner way.
If the error shows up at import time for users, can we trigger it on CI?
> If the error shows up at import time for users, can we trigger it on CI?

I suspect it will only happen on 2.7, which we don't test now. (We should probably still fix it, though.) I wrote a little BASH solution, will open a PR to see the output.

Resolving patch:
diff --git a/scipy/io/__init__.py b/scipy/io/__init__.py
--- a/scipy/io/__init__.py
+++ b/scipy/io/__init__.py
@@ -1,5 +1,5 @@
-# -*- encoding:utf-8 -*-
-"""
+# -*- coding: utf-8 -*-
+u"""
 ==================================
 Input and output (:mod:`scipy.io`)
 ==================================
diff --git a/scipy/stats/_continuous_distns.py b/scipy/stats/_continuous_distns.py
--- a/scipy/stats/_continuous_distns.py
+++ b/scipy/stats/_continuous_distns.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
 #
 # Author:  Travis Oliphant  2002-2011 with contributions from
 #          SciPy Developers 2004-2011
@@ -3342,7 +3343,7 @@ class norminvgauss_gen(rv_continuous):
 
     O. Barndorff-Nielsen, "Normal Inverse Gaussian Distributions and Stochastic
     Volatility Modelling", Scandinavian Journal of Statistics, Vol. 24,
-    pp. 1–13, 1997.
+    pp. 1-13, 1997.
 
     %(example)s
 
@@ -3379,7 +3380,7 @@ def _stats(self, a, b):
 
 
 class invweibull_gen(rv_continuous):
-    r"""An inverted Weibull continuous random variable.
+    u"""An inverted Weibull continuous random variable.
 
     This distribution is also known as the Fréchet distribution or the
     type II extreme value distribution.
@@ -3392,7 +3393,7 @@ class invweibull_gen(rv_continuous):
 
     .. math::
 
-        f(x, c) = c x^{-c-1} \exp(-x^{-c})
+        f(x, c) = c x^{-c-1} \\exp(-x^{-c})
 
     for :math:`x > 0`, :math:`c > 0`.
 
@@ -4002,9 +4003,9 @@ def _cdf(self, x, alpha, beta):
                 data_out[data_mask] = np.array([levy_stable._cdf_single_value_zolotarev(_x, _alpha, _beta)
                             for _x, _alpha, _beta in data_subset]).reshape(len(data_subset), 1)
             else:
-                warnings.warn('FFT method is considered experimental for ' +
-                              'cumulative distribution function ' +
-                              'evaluations. Use Zolotarev’s method instead).',
+                warnings.warn(u'FFT method is considered experimental for ' +
+                              u'cumulative distribution function ' +
+                              u'evaluations. Use Zolotarev’s method instead).',
                               RuntimeWarning)
                 _alpha, _beta = pair
                 _x = data_subset[:,(0,)]
diff --git a/scipy/stats/_stats_mstats_common.py b/scipy/stats/_stats_mstats_common.py
--- a/scipy/stats/_stats_mstats_common.py
+++ b/scipy/stats/_stats_mstats_common.py
@@ -11,6 +11,7 @@
                                                    'rvalue', 'pvalue',
                                                    'stderr'))
 
+
 def linregress(x, y=None):
     """
     Calculate a linear least-squares regression for two sets of measurements.
@@ -327,7 +328,7 @@ def siegelslopes(y, x=None, method="hierarchical"):
 
     .. [2] A. Stein and M. Werman, "Finding the repeated median regression
            line", Proceedings of the Third Annual ACM-SIAM Symposium on
-           Discrete Algorithms, pp. 409–413, 1992.
+           Discrete Algorithms, pp. 409-413, 1992.
 
     Examples
     --------


Test patch: