Skip to content

Commit

Permalink
Merge pull request #1214 from DKilkenny/six_removes
Browse files Browse the repository at this point in the history
Removing Six imports
  • Loading branch information
swryan committed Mar 4, 2020
2 parents 5fc38bc + 216a01c commit 1553fe0
Show file tree
Hide file tree
Showing 166 changed files with 599 additions and 944 deletions.
1 change: 0 additions & 1 deletion benchmark/benchmark_multipoint.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import time
import unittest
from six.moves import range

import numpy as np

Expand Down
5 changes: 2 additions & 3 deletions openmdao/approximation_schemes/approximation_scheme.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Base class used to define the interface for derivative approximation schemes."""
from six import iteritems
from collections import defaultdict
from scipy.sparse import coo_matrix
import numpy as np
Expand Down Expand Up @@ -149,7 +148,7 @@ def _init_colored_approximations(self, system):

data = None
keys = set()
for key, apprx in iteritems(self._exec_dict):
for key, apprx in self._exec_dict.items():
if key[0] in wrt_matches:
if data is None:
# data is the same for all colored approxs so we only need the first
Expand Down Expand Up @@ -353,7 +352,7 @@ def _compute_approximations(self, system, jac, total, under_cs):
data, results_array, total)

if is_parallel:
for of, (oview, out_idxs, _, _) in iteritems(J['ofs']):
for of, (oview, out_idxs, _, _) in J['ofs'].items():
if owns[of] == iproc:
results[(of, wrt)].append(
(i_count,
Expand Down
5 changes: 2 additions & 3 deletions openmdao/approximation_schemes/complex_step.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Complex Step derivative approximations."""
from six import iteritems, itervalues
from six.moves import range

from collections import defaultdict

import numpy as np
Expand Down Expand Up @@ -113,7 +112,7 @@ def compute_approximations(self, system, jac, total=False):

fd = self._fd = FiniteDifference()
empty = {}
for lst in itervalues(self._exec_dict):
for lst in self._exec_dict.values():
for apprx in lst:
fd.add_approximation(apprx[0], system, empty)

Expand Down
2 changes: 0 additions & 2 deletions openmdao/approximation_schemes/finite_difference.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Finite difference derivative approximations."""
from collections import namedtuple, defaultdict
from six import iteritems
from six.moves import range, zip

import numpy as np

Expand Down
19 changes: 4 additions & 15 deletions openmdao/code_review/test_lint_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import textwrap
import collections
import re
from six import PY3

try:
from numpydoc.docscrape import NumpyDocString
Expand Down Expand Up @@ -239,12 +238,8 @@ def check_parameters(self, argspec, numpy_doc_string):
# Do require documentation of *args and **kwargs
if argspec.varargs:
arg_set |= {'*' + argspec.varargs}
if PY3:
if argspec.varkw:
arg_set |= {'**' + argspec.varkw}
else:
if argspec.keywords:
arg_set |= {'**' + argspec.keywords}
if argspec.varkw:
arg_set |= {'**' + argspec.varkw}

if len(arg_set) >= 1:
if not numpy_doc_string['Parameters']:
Expand Down Expand Up @@ -366,10 +361,7 @@ def check_method(self, dir_name, file_name,
with information about every failure. Form is
{ 'dir_name/file_name:class_name.method_name': [ messages ] }
"""
if PY3:
argspec = inspect.getfullargspec(method)
else:
argspec = inspect.getargspec(method)
argspec = inspect.getfullargspec(method)
doc = inspect.getdoc(method)

new_failures = []
Expand Down Expand Up @@ -465,10 +457,7 @@ def check_function(self, dir_name, file_name, func_name, func, failures):
{ 'dir_name/file_name:class_name.method_name': [ messages ] }
"""

if PY3:
argspec = inspect.getfullargspec(func)
else:
argspec = inspect.getargspec(func)
argspec = inspect.getfullargspec(func)
doc = inspect.getdoc(func)

new_failures = []
Expand Down
7 changes: 3 additions & 4 deletions openmdao/components/add_subtract_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Definition of the Add/Subtract Component.
"""
import collections
from six import string_types

import numpy as np
from scipy import sparse as sp
Expand Down Expand Up @@ -71,7 +70,7 @@ def __init__(self, output_name=None, input_names=None, vec_size=1, length=1,

self._add_systems = []

if isinstance(output_name, string_types):
if isinstance(output_name, str):
self._add_systems.append((output_name, input_names, vec_size, length, val,
scaling_factors, kwargs))
elif isinstance(output_name, collections.Iterable):
Expand Down Expand Up @@ -174,7 +173,7 @@ def _post_configure(self):

for (output_name, input_names, vec_size, length, val,
scaling_factors, kwargs) in self._add_systems:
if isinstance(input_names, string_types):
if isinstance(input_names, str):
input_names = [input_names]

units = kwargs['units']
Expand Down Expand Up @@ -218,7 +217,7 @@ def compute(self, inputs, outputs):
complexify = self.options['complex']
for (output_name, input_names, vec_size, length, val, scaling_factors,
kwargs) in self._add_systems:
if isinstance(input_names, string_types):
if isinstance(input_names, str):
input_names = [input_names]

if scaling_factors is None:
Expand Down
7 changes: 2 additions & 5 deletions openmdao/components/akima_spline_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
https://github.com/andrewning/akima
"""
from six.moves import range
from six import string_types

import numpy as np

from openmdao.core.explicitcomponent import ExplicitComponent
Expand Down Expand Up @@ -99,9 +96,9 @@ def initialize(self):
desc="When True, the interpolated x grid is a component input.")
self.options.declare('input_xcp', types=bool, default=False,
desc="When True, the x control point grid is a component input.")
self.options.declare('units', types=string_types, default=None, allow_none=True,
self.options.declare('units', types=str, default=None, allow_none=True,
desc="Units to use for the y and ycp variables.")
self.options.declare('x_units', types=string_types, default=None, allow_none=True,
self.options.declare('x_units', types=str, default=None, allow_none=True,
desc="Units to use for the x and xcp variables.")
self.options.declare('delta_x', default=0.1,
desc="half-width of the smoothing interval added in the valley of "
Expand Down
7 changes: 3 additions & 4 deletions openmdao/components/balance_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from types import FunctionType
from numbers import Number
from six import iteritems

import numpy as np

Expand Down Expand Up @@ -153,7 +152,7 @@ def _post_configure(self):
# set static mode to False because we are doing things that would normally be done in setup
self._static_mode = False

for name, options in iteritems(self._state_vars):
for name, options in self._state_vars.items():

meta = self.add_output(name, **options['kwargs'])

Expand Down Expand Up @@ -208,7 +207,7 @@ def apply_nonlinear(self, inputs, outputs, residuals):
else:
self._scale_factor = self._scale_factor.real

for name, options in iteritems(self._state_vars):
for name, options in self._state_vars.items():
lhs = inputs[options['lhs_name']]
rhs = inputs[options['rhs_name']]

Expand Down Expand Up @@ -247,7 +246,7 @@ def linearize(self, inputs, outputs, jacobian):
else:
self._dscale_drhs = self._dscale_drhs.real

for name, options in iteritems(self._state_vars):
for name, options in self._state_vars.items():
lhs_name = options['lhs_name']
rhs_name = options['rhs_name']

Expand Down
4 changes: 1 addition & 3 deletions openmdao/components/bsplines_comp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
Simple B-spline component for interpolation.
"""
from six import string_types

import numpy as np
from scipy.sparse import csc_matrix, csr_matrix

Expand Down Expand Up @@ -149,7 +147,7 @@ def initialize(self):
desc="Name to use for the input variable (control points).")
self.options.declare('out_name', types=str, default='h',
desc="Name to use for the output variable (interpolated points).")
self.options.declare('units', types=string_types, default=None, allow_none=True,
self.options.declare('units', types=str, default=None, allow_none=True,
desc="Units to use for the input and output variables.")
self.options.declare('distribution', default='sine', values=['uniform', 'sine'],
desc="Choice of spatial distribution to use for placing the control "
Expand Down
14 changes: 6 additions & 8 deletions openmdao/components/cross_product_comp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Definition of the Cross Product Component."""

from six import string_types

import numpy as np

from openmdao.core.explicitcomponent import ExplicitComponent
Expand Down Expand Up @@ -33,17 +31,17 @@ def initialize(self):
"""
self.options.declare('vec_size', types=int, default=1,
desc='The number of points at which the cross product is computed')
self.options.declare('a_name', types=string_types, default='a',
self.options.declare('a_name', types=str, default='a',
desc='The variable name for vector a.')
self.options.declare('b_name', types=string_types, default='b',
self.options.declare('b_name', types=str, default='b',
desc='The variable name for vector b.')
self.options.declare('c_name', types=string_types, default='c',
self.options.declare('c_name', types=str, default='c',
desc='The variable name for vector c.')
self.options.declare('a_units', types=string_types, default=None, allow_none=True,
self.options.declare('a_units', types=str, default=None, allow_none=True,
desc='The units for vector a.')
self.options.declare('b_units', types=string_types, default=None, allow_none=True,
self.options.declare('b_units', types=str, default=None, allow_none=True,
desc='The units for vector b.')
self.options.declare('c_units', types=string_types, default=None, allow_none=True,
self.options.declare('c_units', types=str, default=None, allow_none=True,
desc='The units for vector c.')

self._k = np.array([[0, 0, 0, -1, 0, 1],
Expand Down
4 changes: 1 addition & 3 deletions openmdao/components/demux_comp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""Definition of the Demux Component."""


from six import iteritems

import numpy as np

from openmdao.core.explicitcomponent import ExplicitComponent
Expand Down Expand Up @@ -75,7 +73,7 @@ def _post_configure(self):
opts = self.options
vec_size = opts['vec_size']

for var, options in iteritems(self._vars):
for var, options in self._vars.items():
kwgs = dict(options)
shape = options['shape']
size = np.prod(shape)
Expand Down
15 changes: 6 additions & 9 deletions openmdao/components/dot_product_comp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"""Definition of the Dot Product Component."""


from six import string_types

import numpy as np

from openmdao.core.explicitcomponent import ExplicitComponent
Expand Down Expand Up @@ -30,17 +27,17 @@ def initialize(self):
desc='The number of points at which the dot product is computed')
self.options.declare('length', types=int, default=3,
desc='The length of vectors a and b')
self.options.declare('a_name', types=string_types, default='a',
self.options.declare('a_name', types=str, default='a',
desc='The variable name for input vector a.')
self.options.declare('b_name', types=string_types, default='b',
self.options.declare('b_name', types=str, default='b',
desc='The variable name for input vector b.')
self.options.declare('c_name', types=string_types, default='c',
self.options.declare('c_name', types=str, default='c',
desc='The variable name for output vector c.')
self.options.declare('a_units', types=string_types, default=None, allow_none=True,
self.options.declare('a_units', types=str, default=None, allow_none=True,
desc='The units for vector a.')
self.options.declare('b_units', types=string_types, default=None, allow_none=True,
self.options.declare('b_units', types=str, default=None, allow_none=True,
desc='The units for vector b.')
self.options.declare('c_units', types=string_types, default=None, allow_none=True,
self.options.declare('c_units', types=str, default=None, allow_none=True,
desc='The units for vector c.')

def setup(self):
Expand Down
7 changes: 3 additions & 4 deletions openmdao/components/eq_constraint_comp.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Define the EQConstraintComp class."""

from numbers import Number
from six import iteritems

import numpy as np

Expand Down Expand Up @@ -111,7 +110,7 @@ def _post_configure(self):
# set static mode to False because we are doing things that would normally be done in setup
self._static_mode = False

for name, options in iteritems(self._output_vars):
for name, options in self._output_vars.items():

meta = self.add_output(name, **options['kwargs'])

Expand Down Expand Up @@ -168,7 +167,7 @@ def compute(self, inputs, outputs):
else:
self._scale_factor = self._scale_factor.real

for name, options in iteritems(self._output_vars):
for name, options in self._output_vars.items():
lhs = inputs[options['lhs_name']]
rhs = inputs[options['rhs_name']]

Expand Down Expand Up @@ -205,7 +204,7 @@ def compute_partials(self, inputs, partials):
else:
self._dscale_drhs = self._dscale_drhs.real

for name, options in iteritems(self._output_vars):
for name, options in self._output_vars.items():
lhs_name = options['lhs_name']
rhs_name = options['rhs_name']

Expand Down
5 changes: 1 addition & 4 deletions openmdao/components/exec_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import numpy as np
from numpy import ndarray, imag, complex as npcomplex

from six import string_types
from six.moves import range

from openmdao.core.explicitcomponent import ExplicitComponent
from openmdao.utils.units import valid_units
from openmdao.utils.general_utils import warn_deprecation
Expand Down Expand Up @@ -222,7 +219,7 @@ def __init__(self, exprs=[], **kwargs):
# if complex step is used for derivatives, this is the stepsize
self.complex_stepsize = 1.e-40

if isinstance(exprs, string_types):
if isinstance(exprs, str):
exprs = [exprs]

self._exprs = exprs[:]
Expand Down
2 changes: 0 additions & 2 deletions openmdao/components/interp_util/interp.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
Based on Tables in NPSS, and was added to bridge the gap between some of the slower scipy
implementations.
"""
from six.moves import range

import numpy as np

from openmdao.components.interp_util.interp_akima import InterpAkima
Expand Down
2 changes: 0 additions & 2 deletions openmdao/components/interp_util/interp_akima.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
Based on NPSS implementation, with improvements from Andrew Ning (BYU).
"""
from six.moves import range

import numpy as np

from openmdao.components.interp_util.interp_algorithm import InterpAlgorithm
Expand Down
1 change: 0 additions & 1 deletion openmdao/components/interp_util/interp_cubic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Based on NPSS implementation.
"""
from six.moves import range

import numpy as np

Expand Down
1 change: 0 additions & 1 deletion openmdao/components/interp_util/interp_scipy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Grid interpolation using scipy splines."""
from six.moves import range

from scipy import __version__ as scipy_version
try:
Expand Down
2 changes: 0 additions & 2 deletions openmdao/components/ks_comp.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
"""
KS Function Component.
"""
from six.moves import range

import numpy as np

from openmdao.core.explicitcomponent import ExplicitComponent
Expand Down
1 change: 0 additions & 1 deletion openmdao/components/linear_system_comp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Define the LinearSystemComp class."""
from six.moves import range

import numpy as np
from scipy import linalg
Expand Down
Loading

0 comments on commit 1553fe0

Please sign in to comment.