Skip to content

Commit

Permalink
Remove use of six Py2-Py3-compatability package
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholmer committed Sep 7, 2018
1 parent 9b85aa6 commit 3fe7aeb
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 55 deletions.
12 changes: 6 additions & 6 deletions taxcalc/calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import json
import re
import copy
import six

import numpy as np
import pandas as pd
from taxcalc.functions import (TaxInc, SchXYZTax, GainsTax, AGIsurtax,
Expand Down Expand Up @@ -1133,7 +1133,7 @@ def decile_graph(self, calc,
def read_json_param_objects(reform, assump):
"""
Read JSON reform and assump objects and
return a single dictionary containing six key:dict pairs:
return a single dictionary containing 6 key:dict pairs:
'policy':dict, 'consumption':dict, 'behavior':dict,
'growdiff_baseline':dict, 'growdiff_response':dict, and
'growmodel':dict.
Expand Down Expand Up @@ -1168,7 +1168,7 @@ def read_json_param_objects(reform, assump):
gdiff_base_dict = dict()
gdiff_resp_dict = dict()
growmodel_dict = dict()
elif isinstance(assump, six.string_types):
elif isinstance(assump, str):
if os.path.isfile(assump):
txt = open(assump, 'r').read()
else:
Expand All @@ -1183,7 +1183,7 @@ def read_json_param_objects(reform, assump):
# next process first reform parameter
if reform is None:
rpol_dict = dict()
elif isinstance(reform, six.string_types):
elif isinstance(reform, str):
if os.path.isfile(reform):
txt = open(reform, 'r').read()
else:
Expand Down Expand Up @@ -1653,15 +1653,15 @@ def _convert_parameter_dict(param_key_dict):
# optionally convert lists into np.arrays
year_param = dict()
for pkey, sdict in param_key_dict.items():
if not isinstance(pkey, six.string_types):
if not isinstance(pkey, str):
msg = 'pkey {} in reform is not a string'
raise ValueError(msg.format(pkey))
rdict = dict()
if not isinstance(sdict, dict):
msg = 'pkey {} in reform is not paired with a dict'
raise ValueError(msg.format(pkey))
for skey, val in sdict.items():
if not isinstance(skey, six.string_types):
if not isinstance(skey, str):
msg = 'skey {} in reform is not a string'
raise ValueError(msg.format(skey))
else:
Expand Down
6 changes: 3 additions & 3 deletions taxcalc/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# pylint --disable=locally-disabled decorators.py

import sys
import io
import ast
import inspect
import toolz
from six import StringIO
from taxcalc.policy import Policy


Expand Down Expand Up @@ -84,7 +84,7 @@ def ap_fuc(x_0, x_1, x_2, ...):
-------
a String representing the function
"""
fstr = StringIO()
fstr = io.StringIO()
total_len = len(sigout) + len(sigin)
out_args = ["x_" + str(i) for i in range(0, len(sigout))]
in_args = ["x_" + str(i) for i in range(len(sigout), total_len)]
Expand Down Expand Up @@ -122,7 +122,7 @@ def hl_func(x_0, x_1, x_2, ...):
-------
a String representing the function
"""
fstr = StringIO()
fstr = io.StringIO()
fstr.write("def hl_func(pm, pf")
fstr.write("):\n")
fstr.write(" from pandas import DataFrame\n")
Expand Down
3 changes: 1 addition & 2 deletions taxcalc/growfactors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# pylint --disable=locally-disabled growfactors.py

import os
import six
import numpy as np
import pandas as pd
from taxcalc.utils import read_egg_csv
Expand Down Expand Up @@ -53,7 +52,7 @@ class instance: GrowFactors
def __init__(self, growfactors_filename=FILE_PATH):
# read grow factors from specified growfactors_filename
gfdf = pd.DataFrame()
if isinstance(growfactors_filename, six.string_types):
if isinstance(growfactors_filename, str):
if os.path.isfile(growfactors_filename):
gfdf = pd.read_csv(growfactors_filename,
index_col='YEAR')
Expand Down
3 changes: 1 addition & 2 deletions taxcalc/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import os
import json
import six
import abc
import collections as collect
import numpy as np
Expand Down Expand Up @@ -173,7 +172,7 @@ def set_year(self, year):
year_zero_indexed = year - self._start_year
if hasattr(self, '_vals'):
for name in self._vals:
if isinstance(name, six.string_types):
if isinstance(name, str):
arr = getattr(self, name)
setattr(self, name[1:], arr[year_zero_indexed])

Expand Down
3 changes: 1 addition & 2 deletions taxcalc/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# pycodestyle policy.py
# pylint --disable=locally-disabled policy.py

import six
import numpy as np
from taxcalc.parameters import ParametersBase
from taxcalc.growfactors import GrowFactors
Expand Down Expand Up @@ -511,7 +510,7 @@ def _validate_parameter_values(self, parameters_set):
continue # *_cpi parameter values validated elsewhere
pvalue = getattr(self, pname)
for vop, vval in self._vals[pname]['range'].items():
if isinstance(vval, six.string_types):
if isinstance(vval, str):
vvalue = getattr(self, vval)
else:
vvalue = np.full(pvalue.shape, vval)
Expand Down
7 changes: 3 additions & 4 deletions taxcalc/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import os
import json
import six
import numpy as np
import pandas as pd
from taxcalc.growfactors import GrowFactors
Expand Down Expand Up @@ -423,7 +422,7 @@ def _read_data(self, data, exact_calcs):
# read specified data
if isinstance(data, pd.DataFrame):
taxdf = data
elif isinstance(data, six.string_types):
elif isinstance(data, str):
if os.path.isfile(data):
taxdf = pd.read_csv(data)
else:
Expand Down Expand Up @@ -503,7 +502,7 @@ def _read_weights(self, weights):
return
if isinstance(weights, pd.DataFrame):
WT = weights
elif isinstance(weights, six.string_types):
elif isinstance(weights, str):
weights_path = os.path.join(Records.CUR_PATH, weights)
if os.path.isfile(weights_path):
WT = pd.read_csv(weights_path)
Expand All @@ -526,7 +525,7 @@ def _read_ratios(self, ratios):
if ratios is None:
setattr(self, 'ADJ', pd.DataFrame({'nothing': []}))
return
if isinstance(ratios, six.string_types):
if isinstance(ratios, str):
ratios_path = os.path.join(Records.CUR_PATH, ratios)
if os.path.isfile(ratios_path):
ADJ = pd.read_csv(ratios_path,
Expand Down
5 changes: 2 additions & 3 deletions taxcalc/simpletaxio.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import sys
import re
import six
import pandas as pd
from taxcalc.policy import Policy
from taxcalc.records import Records
Expand Down Expand Up @@ -67,7 +66,7 @@ def __init__(self,
"""
# pylint: disable=too-many-arguments
# check that input_filename is a string
if not isinstance(input_filename, six.string_types):
if not isinstance(input_filename, str):
msg = 'SimpleTaxIO.ctor input_filename is not a string'
raise ValueError(msg)
# construct output_filename and delete old output file if it exists
Expand All @@ -76,7 +75,7 @@ def __init__(self,
ref = ''
self._using_reform_file = True
else: # if reform is not None
if isinstance(reform, six.string_types):
if isinstance(reform, str):
if reform.endswith('.json'):
ref = '-{}'.format(reform[:-5])
else:
Expand Down
13 changes: 6 additions & 7 deletions taxcalc/taxcalcio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import gc
import copy
import sqlite3
import six
import numpy as np
import pandas as pd
from taxcalc.policy import Policy
Expand Down Expand Up @@ -75,7 +74,7 @@ def __init__(self, input_data, tax_year, baseline, reform, assump,
inp = 'x'
self.puf_input_data = False
self.cps_input_data = False
if isinstance(input_data, six.string_types):
if isinstance(input_data, str):
# remove any leading directory path from INPUT filename
fname = os.path.basename(input_data)
# check if fname ends with ".csv"
Expand All @@ -99,7 +98,7 @@ def __init__(self, input_data, tax_year, baseline, reform, assump,
bas = '-x'
if baseline is None:
bas = '-#'
elif isinstance(baseline, six.string_types):
elif isinstance(baseline, str):
# remove any leading directory path from BASELINE filename
fname = os.path.basename(baseline)
# check if fname ends with ".json"
Expand All @@ -120,7 +119,7 @@ def __init__(self, input_data, tax_year, baseline, reform, assump,
if reform is None:
self.specified_reform = False
ref = '-#'
elif isinstance(reform, six.string_types):
elif isinstance(reform, str):
self.specified_reform = True
# split any compound reform into list of simple reforms
refnames = list()
Expand Down Expand Up @@ -153,7 +152,7 @@ def __init__(self, input_data, tax_year, baseline, reform, assump,
asm = '-x'
if assump is None:
asm = '-#'
elif isinstance(assump, six.string_types):
elif isinstance(assump, str):
# remove any leading directory path from ASSUMP filename
fname = os.path.basename(assump)
# check if fname ends with ".json"
Expand All @@ -172,7 +171,7 @@ def __init__(self, input_data, tax_year, baseline, reform, assump,
# check name and existence of OUTDIR
if outdir is None:
valid_outdir = True
elif isinstance(outdir, six.string_types):
elif isinstance(outdir, str):
# check existence of OUTDIR
if os.path.isdir(outdir):
valid_outdir = True
Expand Down Expand Up @@ -381,7 +380,7 @@ def custom_dump_variables(self, tcdumpvars_str):
contains the contents of the tcdumpvars file in the current directory.
Also, builds self.errmsg if any custom variables are not valid.
"""
assert isinstance(tcdumpvars_str, six.string_types)
assert isinstance(tcdumpvars_str, str)
self.errmsg = ''
# change some common delimiter characters into spaces
dump_vars_str = tcdumpvars_str.replace(',', ' ')
Expand Down
3 changes: 1 addition & 2 deletions taxcalc/tests/test_calculate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from io import StringIO
import tempfile
import copy
import six
import pytest
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -886,7 +885,7 @@ def test_reform_documentation():
params = Calculator.read_json_param_objects(reform_json, assump_json)
assert isinstance(params, dict)
doc = Calculator.reform_documentation(params)
assert isinstance(doc, six.string_types)
assert isinstance(doc, str)
dump = False # set to True to print documentation and force test failure
if dump:
print(doc)
Expand Down
9 changes: 4 additions & 5 deletions taxcalc/tests/test_compatible_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import copy
import pytest
import numpy as np
import six
from taxcalc import Policy, Records, Calculator # pylint: disable=import-error


Expand Down Expand Up @@ -247,23 +246,23 @@ def test_compatible_data(cps_subsample, puf_subsample,
param = allparams_batch[pname]
max_listed = param['range']['max']
# handle links to other params or self
if isinstance(max_listed, six.string_types):
if isinstance(max_listed, str):
if max_listed == 'default':
max_val = param['value'][-1]
else:
max_val = allparams[max_listed]['value'][0]
if not isinstance(max_listed, six.string_types):
if not isinstance(max_listed, str):
if isinstance(param['value'][0], list):
max_val = [max_listed] * len(param['value'][0])
else:
max_val = max_listed
min_listed = param['range']['min']
if isinstance(min_listed, six.string_types):
if isinstance(min_listed, str):
if min_listed == 'default':
min_val = param['value'][-1]
else:
min_val = allparams[min_listed]['value'][0]
if not isinstance(min_listed, six.string_types):
if not isinstance(min_listed, str):
if isinstance(param['value'][0], list):
min_val = [min_listed] * len(param['value'][0])
else:
Expand Down
4 changes: 2 additions & 2 deletions taxcalc/tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import sys
import pytest
from six.moves import reload_module
import importlib
import numpy as np
from pandas import DataFrame
from taxcalc.decorators import *
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_force_no_numba():
nmba = sys.modules.get('numba', None)
sys.modules.update([('numba', mck)])
# Reload the decorators with faked out numba
reload_module(taxcalc.decorators)
importlib.reload(taxcalc.decorators)
# Get access to iterate_jit and force to jit
ij = taxcalc.decorators.iterate_jit
taxcalc.decorators.DO_JIT = True
Expand Down
6 changes: 1 addition & 5 deletions taxcalc/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import re
import ast
import six
from taxcalc import Records # pylint: disable=import-error


Expand All @@ -35,10 +34,7 @@ def visit_FunctionDef(self, node): # pylint: disable=invalid-name
self.fnames.append(self.fname)
self.fargs[self.fname] = list()
for anode in ast.iter_child_nodes(node.args):
if six.PY3:
self.fargs[self.fname].append(anode.arg)
else: # in Python 2 anode is a Name node
self.fargs[self.fname].append(anode.id)
self.fargs[self.fname].append(anode.arg)
self.cvars[self.fname] = list()
for bodynode in node.body:
if isinstance(bodynode, ast.Return):
Expand Down
11 changes: 5 additions & 6 deletions taxcalc/tests/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import os
import json
import math
import six
import numpy as np
import pytest
# pylint: disable=import-error
Expand Down Expand Up @@ -87,17 +86,17 @@ def test_json_file_contents(tests_path, fname):
failures = ''
for pname in allparams:
# all parameter names should be strings
assert isinstance(pname, six.string_types)
assert isinstance(pname, str)
# check that param contains required keys
param = allparams[pname]
assert isinstance(param, dict)
for key in reqkeys:
assert key in param
# check for non-empty long_name and description strings
assert isinstance(param['long_name'], six.string_types)
assert isinstance(param['long_name'], str)
if not param['long_name']:
assert '{} long_name'.format(pname) == 'empty string'
assert isinstance(param['description'], six.string_types)
assert isinstance(param['description'], str)
if not param['description']:
assert '{} description'.format(pname) == 'empty string'
# check that row_var is FLPDYR
Expand All @@ -123,10 +122,10 @@ def test_json_file_contents(tests_path, fname):
assert len(value) == len(rowlabel)
# check that col_var and col_label are consistent
cvar = param['col_var']
assert isinstance(cvar, six.string_types)
assert isinstance(cvar, str)
clab = param['col_label']
if cvar == '':
assert isinstance(clab, six.string_types) and clab == ''
assert isinstance(clab, str) and clab == ''
else:
assert isinstance(clab, list)
# check different possible col_var values
Expand Down
Loading

0 comments on commit 3fe7aeb

Please sign in to comment.