Skip to content

Commit 2f6376e

Browse files
alexandermorgancwhanse
authored andcommitted
remove python 2 lines (pvlib#757)
* Resolve merge conflicts. The upstream what's new file had been updated. * Remove py2 and Windows checks. Removed because python 2 is no longer supported, and this let us remove the checks for Windows too. * Remove from __future__ import print_function. * Remove from __future__ import division. * Revert "Remove py2 and Windows checks." This reverts commit a762fc3. * Remove has_python2 checks. * Remove duplicate line in what's new file. * Remove python2-sensitive imports. * Remove out-of-date python2 comment. * Import JSONDecodeError directly in py3 way. * Change Tkinter import (py2) to tkinter (py3). * Update import configparser to only py3 version. * Update documentation comment. * Remove strict arguments. The case where these were relevant (Windows build using Python 2) is no longer used because Python 2 is no longer supported. * Remove platform_is_windows import. It is no longer used. * Set strict arg to True for two tests. * Fix indentation mistake. Convert tabs to spaces. * Revert "Remove from __future__ import print_function." This reverts commit 0508b33. This also undoes the changes to how configparser is imported.
1 parent 733e489 commit 2f6376e

15 files changed

+16
-67
lines changed

pvlib/atmosphere.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
absolute airmass and to determine pressure from altitude or vice versa.
44
"""
55

6-
from __future__ import division
7-
86
from warnings import warn
97

108
import numpy as np
@@ -211,8 +209,7 @@ def get_relative_airmass(zenith, model='kastenyoung1989'):
211209
Sandia Report, (2012).
212210
'''
213211

214-
# need to filter first because python 2.7 does not support raising a
215-
# negative number to a negative power.
212+
# set zenith values greater than 90 to nans
216213
z = np.where(zenith > 90, np.nan, zenith)
217214
zenith_rad = np.radians(z)
218215

pvlib/clearsky.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
to calculate clear sky GHI, DNI, and DHI.
44
"""
55

6-
from __future__ import division
7-
86
import os
97
from collections import OrderedDict
108
import calendar

pvlib/iotools/ecmwf_macc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Read data from ECMWF MACC Reanalysis.
33
"""
44

5-
from __future__ import division
65
import threading
76
import pandas as pd
87

pvlib/iotools/epw.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
"""
44

55
import io
6-
7-
try:
8-
# python 2 compatibility
9-
from urllib2 import urlopen, Request
10-
except ImportError:
11-
from urllib.request import urlopen, Request
12-
6+
from urllib.request import urlopen, Request
137
import pandas as pd
148

159

pvlib/iotools/psm3.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
import io
88
import requests
99
import pandas as pd
10-
# Python-2 compatible JSONDecodeError
11-
try:
12-
from json import JSONDecodeError
13-
except ImportError:
14-
JSONDecodeError = ValueError
10+
from json import JSONDecodeError
1511

1612
URL = "http://developer.nrel.gov/api/solar/nsrdb_psm3_download.csv"
1713

pvlib/iotools/surfrad.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,7 @@
22
Import functions for NOAA SURFRAD Data.
33
"""
44
import io
5-
6-
try:
7-
# python 2 compatibility
8-
from urllib2 import urlopen, Request
9-
except ImportError:
10-
from urllib.request import urlopen, Request
11-
5+
from urllib.request import urlopen, Request
126
import pandas as pd
137
import numpy as np
148

pvlib/iotools/tmy.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,7 @@
55
import datetime
66
import io
77
import re
8-
9-
try:
10-
# python 2 compatibility
11-
from urllib2 import urlopen, Request
12-
except ImportError:
13-
from urllib.request import urlopen, Request
14-
8+
from urllib.request import urlopen, Request
159
import dateutil
1610
import pandas as pd
1711

@@ -160,7 +154,7 @@ def read_tmy3(filename=None, coerce_year=None, recolumn=True):
160154
try:
161155
filename = _interactive_load()
162156
except ImportError:
163-
raise ImportError('Interactive load failed. Tkinter not supported '
157+
raise ImportError('Interactive load failed. tkinter not supported '
164158
'on this system. Try installing X-Quartz and '
165159
'reloading')
166160

@@ -210,9 +204,9 @@ def read_tmy3(filename=None, coerce_year=None, recolumn=True):
210204

211205

212206
def _interactive_load():
213-
import Tkinter
214-
from tkFileDialog import askopenfilename
215-
Tkinter.Tk().withdraw() # Start interactive file input
207+
import tkinter
208+
from tkinter.filedialog import askopenfilename
209+
tkinter.Tk().withdraw() # Start interactive file input
216210
return askopenfilename()
217211

218212

@@ -406,7 +400,7 @@ def read_tmy2(filename):
406400
try:
407401
filename = _interactive_load()
408402
except ImportError:
409-
raise ImportError('Interactive load failed. Tkinter not supported '
403+
raise ImportError('Interactive load failed. tkinter not supported '
410404
'on this system. Try installing X-Quartz and '
411405
'reloading')
412406

pvlib/irradiance.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
irradiance, and total irradiance under various conditions.
55
"""
66

7-
from __future__ import division
8-
97
import datetime
108
from collections import OrderedDict
119
from functools import partial

pvlib/pvsystem.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,10 @@
33
performance of PV modules and inverters.
44
"""
55

6-
from __future__ import division
7-
86
from collections import OrderedDict
97
import io
108
import os
11-
try:
12-
from urllib2 import urlopen
13-
except ImportError:
14-
from urllib.request import urlopen
15-
9+
from urllib.request import urlopen
1610
import numpy as np
1711
import pandas as pd
1812

@@ -1787,14 +1781,8 @@ def retrieve_sam(name=None, path=None):
17871781
else:
17881782
csvdata = path
17891783
elif name is None and path is None:
1790-
try:
1791-
# python 2
1792-
import Tkinter as tkinter
1793-
from tkFileDialog import askopenfilename
1794-
except ImportError:
1795-
# python 3
1796-
import tkinter
1797-
from tkinter.filedialog import askopenfilename
1784+
import tkinter
1785+
from tkinter.filedialog import askopenfilename
17981786

17991787
tkinter.Tk().withdraw()
18001788
csvdata = askopenfilename()

pvlib/solarposition.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# Tony Lorenzo (@alorenzo175), University of Arizona, 2015
99
# Cliff hansen (@cwhanse), Sandia National Laboratories, 2018
1010

11-
from __future__ import division
1211
import os
1312
import datetime as dt
1413
try:

pvlib/spa.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# Contributors:
77
# Created by Tony Lorenzo (@alorenzo175), Univ. of Arizona, 2015
88

9-
from __future__ import division
109
import os
1110
import threading
1211
import warnings

pvlib/test/conftest.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ def inner():
4141
data_dir = os.path.join(test_dir, os.pardir, 'data')
4242

4343

44-
has_python2 = parse_version(platform.python_version()) < parse_version('3')
45-
4644
platform_is_windows = platform.system() == 'Windows'
4745
skip_windows = pytest.mark.skipif(platform_is_windows,
4846
reason='does not run on windows')

pvlib/test/test_conftest.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import pytest
22

3-
from conftest import fail_on_pvlib_version, platform_is_windows, has_python2
3+
from conftest import fail_on_pvlib_version
44

55

6-
# allow xpass for python 2 on windows
7-
@pytest.mark.xfail(strict=(not (platform_is_windows and has_python2)),
6+
@pytest.mark.xfail(strict=True,
87
reason='fail_on_pvlib_version should cause test to fail')
98
@fail_on_pvlib_version('0.0')
109
def test_fail_on_pvlib_version():
@@ -16,8 +15,7 @@ def test_fail_on_pvlib_version_pass():
1615
pass
1716

1817

19-
@pytest.mark.xfail(strict=(not (platform_is_windows and has_python2)),
20-
reason='ensure that the test is called')
18+
@pytest.mark.xfail(strict=True, reason='ensure that the test is called')
2119
@fail_on_pvlib_version('100000.0')
2220
def test_fail_on_pvlib_version_fail_in_test():
2321
raise Exception

pvlib/test/test_ecmwf_macc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
tests for :mod:`pvlib.iotools.ecmwf_macc`
33
"""
44

5-
from __future__ import division
65
import os
76
import datetime
87
import numpy as np

pvlib/tracking.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from __future__ import division
2-
31
import numpy as np
42
import pandas as pd
53

0 commit comments

Comments
 (0)