Skip to content

Commit a3538c7

Browse files
committed
drop support for Python 2.7.x
1 parent 730f41c commit a3538c7

File tree

7 files changed

+13
-41
lines changed

7 files changed

+13
-41
lines changed

changelog.rst

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ latest
55

66
Yet to be versioned and released. Only available from *dev* branch until then.
77

8+
.. rubric:: General
9+
10+
* drop support for Python 2.7.x
11+
812
.. rubric:: Big fixes
913

1014
* fix bug in output writing for `montecarlo` due to change in behaviour in `spotpy`

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
numpy>=1.16
22
scipy
3-
future

setup.py

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ def requirements(filename):
4646
'Operating System :: Microsoft :: Windows',
4747
'Operating System :: POSIX :: Linux',
4848
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
49-
'Programming Language :: Python :: 2',
50-
'Programming Language :: Python :: 2.7',
5149
'Programming Language :: Python :: 3',
5250
'Programming Language :: Python :: 3.5',
5351
'Programming Language :: Python :: 3.6',

smartpy/inout.py

+4-27
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
from datetime import datetime, timedelta
2424
import numpy as np
2525
from collections import OrderedDict
26-
import sys
27-
import io
2826
import argparse
2927
try:
3028
from netCDF4 import Dataset
@@ -36,27 +34,6 @@
3634
from .version import __version__
3735

3836

39-
def open_csv_rb(my_file):
40-
if sys.version_info[0] < 3:
41-
return io.open(my_file, 'rb')
42-
else:
43-
return io.open(my_file, 'r', encoding='utf8')
44-
45-
46-
def open_csv_wb(my_file):
47-
if sys.version_info[0] < 3:
48-
return io.open(my_file, 'wb')
49-
else:
50-
return io.open(my_file, 'w', newline='', encoding='utf8')
51-
52-
53-
def open_csv_ab(my_file):
54-
if sys.version_info[0] < 3:
55-
return io.open(my_file, 'ab')
56-
else:
57-
return io.open(my_file, 'a', newline='', encoding='utf8')
58-
59-
6037
def get_dict_rain_series_simu(file_location, file_format, start_simu, end_simu, time_delta_simu):
6138
dict_rain, start_data, end_data, time_delta_data = read_rain_file(file_location, file_format)
6239

@@ -202,7 +179,7 @@ def read_flow_file(file_location, file_format):
202179
def read_simulation_settings_file(file_location):
203180
my_dict_args = dict()
204181
try:
205-
with open_csv_rb(file_location) as my_file:
182+
with open(file_location, 'r', encoding='utf8') as my_file:
206183
my_reader = DictReader(my_file)
207184
for row in my_reader:
208185
my_dict_args[row['ARGUMENT']] = row['VALUE']
@@ -216,7 +193,7 @@ def read_simulation_settings_file(file_location):
216193

217194
def read_csv_time_series_with_delta_check(csv_file, key_header, val_header):
218195
try:
219-
with open_csv_rb(csv_file) as my_file:
196+
with open(csv_file, 'r', encoding='utf8') as my_file:
220197
my_dict_data = dict()
221198
my_list_dt = list()
222199
my_reader = DictReader(my_file)
@@ -258,7 +235,7 @@ def read_netcdf_time_series_with_delta_check(netcdf_file, key_variable, val_vari
258235

259236
def read_csv_time_series_with_missing_check(csv_file, key_header, val_header):
260237
try:
261-
with open_csv_rb(csv_file) as my_file:
238+
with open(csv_file, 'r', encoding='utf8') as my_file:
262239
my_dict_data = OrderedDict()
263240
my_reader = DictReader(my_file)
264241
try:
@@ -314,7 +291,7 @@ def write_flow_file_from_nds(series_report, discharge, the_file, out_file_format
314291

315292

316293
def write_flow_csv_file_from_nds(series_report, discharge, csv_file):
317-
with open_csv_wb(csv_file) as my_file:
294+
with open(csv_file, 'w', newline='', encoding='utf8') as my_file:
318295
my_writer = writer(my_file, delimiter=',')
319296
my_writer.writerow(['DateTime', 'flow'])
320297
for dt, val in zip(series_report, discharge):

smartpy/montecarlo/montecarlo.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
Dataset = None
3838

3939
from ..smart import SMART
40-
from ..inout import get_dict_simulation_settings, open_csv_rb, open_csv_wb
40+
from ..inout import get_dict_simulation_settings
4141
from ..objfunctions import groundwater_constraint
4242
from ..version import __version__
4343

@@ -123,7 +123,7 @@ def _init_db(self):
123123
"please install it and retry, or choose another file format.")
124124

125125
else: # fall back on to default option (CSV file)
126-
self.database = open_csv_wb(self.db_file)
126+
self.database = open(self.db_file, 'w', newline='', encoding='utf8')
127127
simu_steps = [dt.strftime('%Y-%m-%d %H:%M:%S') for dt in self.model.flow] if self.save_sim else []
128128
# write header in database file
129129
self.database.write(','.join(self.obj_fn_names + self.param_names + simu_steps) + '\n')
@@ -254,7 +254,7 @@ def _get_sampled_sets_from_file(self, file_location, param_names, obj_fn_names,
254254
params.append([row[param] for param in param_names])
255255
# collect parameter values and objective function values from CSV
256256
else:
257-
with open_csv_rb(file_location) as my_file:
257+
with open(file_location, 'r', encoding='utf8') as my_file:
258258
my_reader = DictReader(my_file)
259259
obj_fns, params = list(), list()
260260
for row in my_reader:

smartpy/parameters.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
from csv import DictReader
2222

23-
from .inout import open_csv_rb
24-
2523

2624
class Parameters(object):
2725
def __init__(self):
@@ -58,7 +56,7 @@ def set_parameters_with_file(self, file_location):
5856
"""
5957
my_dict_par = dict()
6058
try:
61-
with open_csv_rb(file_location) as my_file:
59+
with open(file_location, 'r', encoding='utf8') as my_file:
6260
my_reader = DictReader(my_file)
6361
for row in my_reader:
6462
if row['PAR_NAME'] in self.names:

smartpy/timeframe.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@
1919
# along with SMARTpy. If not, see <http://www.gnu.org/licenses/>.
2020

2121
from builtins import range
22-
import sys
2322
from datetime import datetime, timedelta
2423
import argparse
2524
from collections import OrderedDict
26-
if sys.version_info[0] < 3:
27-
from fractions import gcd
28-
else:
29-
from math import gcd
25+
from math import gcd
3026

3127

3228
class TimeFrame(object):

0 commit comments

Comments
 (0)