Skip to content

Commit

Permalink
Don't compare boolean values to True or False using 'is'
Browse files Browse the repository at this point in the history
  • Loading branch information
Xarthisius committed May 6, 2020
1 parent a0b4b9f commit 65219a6
Show file tree
Hide file tree
Showing 38 changed files with 79 additions and 78 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
with open('README.md') as file:
long_description = file.read()

if check_for_openmp() is True:
if check_for_openmp():
omp_args = ['-fopenmp']
else:
omp_args = None
Expand Down
8 changes: 4 additions & 4 deletions tests/test_install_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ def run_install_script(install_script_path, inst_py3, binary_yt=False):
with open('install_script_edited.sh', 'w') as target:
data = source.read()
for dep in OPTIONAL_DEPS:
if binary_yt is True and dep in YT_SOURCE_ONLY_DEPS:
if binary_yt and dep in YT_SOURCE_ONLY_DEPS:
continue
if dep == 'rockstar':
# compiling rockstar is broken on newer MacOS releases
if platform.mac_ver()[0].startswith(('10.12', '10.13')):
continue
dname = 'INST_%s' % dep.upper()
data = data.replace(dname + '=0', dname + '=1')
if inst_py3 is True:
if inst_py3:
data = data.replace('INST_PY3=0', 'INST_PY3=1')
if binary_yt is False:
if not binary_yt:
data = data.replace('INST_YT_SOURCE=0', 'INST_YT_SOURCE=1')
target.write(data)
shutil.copyfile('install_script_edited.sh', 'install_script.sh')
Expand All @@ -110,7 +110,7 @@ def verify_yt_installation(binary_yt):
yt_dir = yt_dir[0]
python_path = os.sep.join([yt_dir, 'bin', 'python'])
for dep in OPTIONAL_DEPS + REQUIRED_DEPS:
if binary_yt is True and dep in YT_SOURCE_ONLY_DEPS:
if binary_yt and dep in YT_SOURCE_ONLY_DEPS:
continue
if dep == 'git':
git_path = os.sep.join([yt_dir, 'bin', 'git'])
Expand Down
2 changes: 1 addition & 1 deletion yt/analysis_modules/halo_finding/rockstar/rockstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def __init__(self, ts, num_readers = 1, num_writers = None,
mylog.info("https://ui.adsabs.harvard.edu/abs/2013ApJ...762..109B")
ParallelAnalysisInterface.__init__(self)
# Decide how we're working.
if ytcfg.getboolean("yt", "inline") is True:
if ytcfg.getboolean("yt", "inline"):
self.runner = InlineRunner()
else:
self.runner = StandardRunner(num_readers, num_writers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def __init__(self, simulation_ds=None, halos_ds=None, make_analytic=True,
if log_mass_max is None:
self.log_mass_max = 16
# If we're making the analytic function...
if self.make_analytic is True:
if self.make_analytic:
# Try to set cosmological parameters from the simulation dataset
if simulation_ds is not None:
self.omega_matter0 = self.simulation_ds.omega_matter
Expand Down
2 changes: 1 addition & 1 deletion yt/data_objects/analyzer_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class RegisteredTask(type):
def __init__(cls, name, b, d):
type.__init__(cls, name, b, d)
if hasattr(cls, "skip") and cls.skip is False:
if hasattr(cls, "skip") and not cls.skip:
return
analysis_task_registry[cls.__name__] = cls

Expand Down
2 changes: 1 addition & 1 deletion yt/data_objects/construction_data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def get_data(self, fields = None):
[], "io", local_only = True)):
mylog.debug("Adding chunk (%s) to tree (%0.3e GB RAM)",
chunk.ires.size, get_memory_usage()/1024.)
if _units_initialized is False:
if not _units_initialized:
self._initialize_projected_units(fields, chunk)
_units_initialized = True
self._handle_chunk(chunk, fields, tree)
Expand Down
4 changes: 2 additions & 2 deletions yt/data_objects/data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
def sanitize_weight_field(ds, field, weight):
field_object = ds._get_field_info(field)
if weight is None:
if field_object.particle_type is True:
if field_object.particle_type:
weight_field = (field_object.name[0], 'particle_ones')
else:
weight_field = ('index', 'ones')
Expand Down Expand Up @@ -1546,7 +1546,7 @@ def get_data(self, fields=None):
fields_to_get.append(field)
if len(fields_to_get) == 0 and len(fields_to_generate) == 0:
return
elif self._locked is True:
elif self._locked:
raise GenerationInProgress(fields)
# Track which ones we want in the end
ofields = set(list(self.field_data.keys())
Expand Down
4 changes: 2 additions & 2 deletions yt/data_objects/static_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __new__(cls, filename=None, *args, **kwargs):
obj = object.__new__(cls)
elif cache_key not in _cached_datasets:
obj = object.__new__(cls)
if obj._skip_cache is False:
if not obj._skip_cache:
_cached_datasets[cache_key] = obj
else:
obj = _cached_datasets[cache_key]
Expand Down Expand Up @@ -879,7 +879,7 @@ def particles_exist(self):
@property
def particle_type_counts(self):
self.index
if self.particles_exist is False:
if not self.particles_exist:
return {}

# frontends or index implementation can populate this dict while
Expand Down
6 changes: 3 additions & 3 deletions yt/data_objects/time_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,10 @@ def piter(self, storage = None, dynamic = False):
...
"""
if self.parallel is False:
if not self.parallel:
njobs = 1
elif dynamic is False:
if self.parallel is True:
elif not dynamic:
if self.parallel:
njobs = -1
else:
njobs = self.parallel
Expand Down
2 changes: 1 addition & 1 deletion yt/fields/derived_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def __init__(self, name, sampling_type, function, units=None,
self.display_name = display_name
self.not_in_all = not_in_all
self.display_field = display_field
if particle_type is True:
if particle_type:
warnings.warn("particle_type for derived fields "
"has been replaced with sampling_type = 'particle'",
DeprecationWarning)
Expand Down
2 changes: 1 addition & 1 deletion yt/fields/field_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_radius(data, field_prefix, ftype):
# it from a cm**2 array.
np.subtract(data[ftype, "%s%s" % (field_prefix, ax)].in_base(unit_system.name),
center[i], r)
if data.ds.periodicity[i] is True:
if data.ds.periodicity[i]:
np.abs(r, r)
np.subtract(r, DW[i], rdw)
np.abs(rdw, rdw)
Expand Down
4 changes: 2 additions & 2 deletions yt/fields/vector_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _magnitude(field, data):
mag += (data[fn])**2
return np.sqrt(mag)

if particle_type is True:
if particle_type:
sampling_type = 'particle'
else:
sampling_type = 'cell'
Expand Down Expand Up @@ -91,7 +91,7 @@ def _relative_vector(field, data):
return d - bulk[iax]
return _relative_vector

if particle_type is True:
if particle_type:
sampling_type = 'particle'
else:
sampling_type = 'cell'
Expand Down
4 changes: 2 additions & 2 deletions yt/frontends/boxlib/tests/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ def test_maestro_parameters():
assert(type(ds.parameters['plot_base_name']) is str)

# Check boolean parameters: T or F
assert(ds.parameters['use_thermal_diffusion'] is False)
assert(not ds.parameters['use_thermal_diffusion'])
assert(type(ds.parameters['use_thermal_diffusion']) is bool)

assert(ds.parameters['do_burning'] is True)
assert(ds.parameters['do_burning'])
assert(type(ds.parameters['do_burning']) is bool)

# Check a float parameter with a decimal point
Expand Down
2 changes: 1 addition & 1 deletion yt/frontends/ytdata/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def get_data(self, fields=None):
fields_to_get.append(field)
if len(fields_to_get) == 0 and len(fields_to_generate) == 0:
return
elif self._locked is True:
elif self._locked:
raise GenerationInProgress(fields)
# Track which ones we want in the end
ofields = set(list(self.field_data.keys())
Expand Down
4 changes: 2 additions & 2 deletions yt/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def wrapper(*arg, **kw):
mylog.debug('%s took %0.3f s', func.__name__, (t2-t1))
return res
from yt.config import ytcfg
if ytcfg.getboolean("yt","timefunctions") is True:
if ytcfg.getboolean("yt","timefunctions"):
return wrapper
else:
return func
Expand Down Expand Up @@ -1144,7 +1144,7 @@ def matplotlib_style_context(style_name=None, after_reset=False):
def toggle_interactivity():
global interactivity
interactivity = not interactivity
if interactivity is True:
if interactivity:
if '__IPYTHON__' in dir(builtins):
import IPython
shell = IPython.get_ipython()
Expand Down
2 changes: 1 addition & 1 deletion yt/geometry/coordinates/spec_cube_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _spec_axis(ax, x, y):
self.axis_field[self.ds.spec_axis] = _spec_axis

def setup_fields(self, registry):
if self.ds.no_cgs_equiv_length is False:
if not self.ds.no_cgs_equiv_length:
return super(SpectralCubeCoordinateHandler, self
).setup_fields(registry)
for axi, ax in enumerate("xyz"):
Expand Down
2 changes: 1 addition & 1 deletion yt/startup_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def print_help(*args, **kwargs):
help_parser.set_defaults(func=print_help)


if parallel_capable is True:
if parallel_capable:
pass
elif exe_name in \
["mpi4py", "embed_enzo",
Expand Down
2 changes: 1 addition & 1 deletion yt/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def construct_octree_mask(prng=RandomState(0x1d3d3d3), refined=None):

if refined in (None, True):
refined = [True]
if refined is False:
if not refined:
refined = [False]
return refined

Expand Down
2 changes: 1 addition & 1 deletion yt/units/unit_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def _lookup_unit_symbol(symbol_str, unit_symbol_lut):
unit_is_si_prefixable = (symbol_wo_prefix in unit_symbol_lut and
symbol_wo_prefix in prefixable_units)

if unit_is_si_prefixable is True:
if unit_is_si_prefixable:
# lookup successful, it's a symbol with a prefix
unit_data = unit_symbol_lut[symbol_wo_prefix]
prefix_value = unit_prefixes[possible_prefix]
Expand Down
2 changes: 1 addition & 1 deletion yt/units/yt_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def __new__(cls, input_array, input_units=None, registry=None, dtype=None,
bypass_validation=False):
if dtype is None:
dtype = getattr(input_array, 'dtype', np.float64)
if bypass_validation is True:
if bypass_validation:
obj = np.asarray(input_array, dtype=dtype).view(cls)
obj.units = input_units
if registry is not None:
Expand Down
2 changes: 1 addition & 1 deletion yt/utilities/answer_testing/answer_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def sph_answer(ds, ds_str_repr, ds_nparticles, field, weight, ds_obj, axis):
particle_type = True
else:
particle_type = False
if particle_type is False:
if not particle_type:
ppv_hd = pixelized_projection_values(ds, axis, field, weight, ds_obj)
hex_digests['pixelized_projection_values'] = ppv_hd
fv_hd = field_values(ds, field, ds_obj, particle_type=particle_type)
Expand Down
9 changes: 5 additions & 4 deletions yt/utilities/answer_testing/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ def configure(self, options, conf):
run_big_data = options.big_data

def finalize(self, result=None):
if self.store_results is False: return
if not self.store_results:
return
self.storage.dump(self.result_storage)

def help(self):
Expand Down Expand Up @@ -968,7 +969,7 @@ def ffalse(func):
return lambda: None
def ftrue(func):
return func
if run_big_data is False and big_data is True:
if not run_big_data and big_data:
return ffalse
elif not can_run_sim(sim_fn, sim_type, file_check):
return ffalse
Expand All @@ -990,7 +991,7 @@ def ffalse(func):
return lambda: None
def ftrue(func):
return func
if run_big_data is False and big_data is True:
if not run_big_data and big_data:
return ffalse
elif not can_run_ds(ds_fn, file_check):
return ffalse
Expand Down Expand Up @@ -1049,7 +1050,7 @@ def sph_answer(ds, ds_str_repr, ds_nparticles, fields):
else:
particle_type = False
for axis in [0, 1, 2]:
if particle_type is False:
if not particle_type:
yield PixelizedProjectionValuesTest(
ds, axis, field, weight_field,
dobj_name)
Expand Down
6 changes: 3 additions & 3 deletions yt/utilities/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def _print_failed_source_update(reinstall=False):
print(" $ conda update yt")
print()
print("to update your yt installation.")
if reinstall is True:
if reinstall:
print()
print("To update all of your packages, you can do:")
print()
Expand Down Expand Up @@ -1081,11 +1081,11 @@ def __call__(self, args):
ds.print_stats()
vals = {}
if args.field in ds.derived_field_list:
if args.max is True:
if args.max:
vals['min'] = ds.find_max(args.field)
print("Maximum %s: %0.5e at %s" % (args.field,
vals['min'][0], vals['min'][1]))
if args.min is True:
if args.min:
vals['max'] = ds.find_min(args.field)
print("Minimum %s: %0.5e at %s" % (args.field,
vals['max'][0], vals['max'][1]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def read_grid(self, filename):
self.parse_line(line, grid)
if grid['read_type'] == 'vector':
break
if table_read is False:
if not table_read:
line = f.readline()
if 'TABLE' in line.strip().split():
table_read = True
Expand Down
4 changes: 2 additions & 2 deletions yt/utilities/grid_data_format/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _get_backup_file(ds):
# backup file already exists, open it. We use parallel
# h5py if it is available
if communication_system.communicators[-1].size > 1 and \
h5py.get_config().mpi is True:
h5py.get_config().mpi:
mpi4py_communicator = communication_system.communicators[-1].comm
f = h5py.File(backup_filename, "r+", driver='mpio',
comm=mpi4py_communicator)
Expand Down Expand Up @@ -264,7 +264,7 @@ def _create_new_gdf(ds, gdf_path, data_author=None, data_comment=None,
# h5py if it is available.
###
if communication_system.communicators[-1].size > 1 and \
h5py.get_config().mpi is True:
h5py.get_config().mpi:
mpi4py_communicator = communication_system.communicators[-1].comm
f = h5py.File(gdf_path, "w", driver='mpio',
comm=mpi4py_communicator)
Expand Down
4 changes: 2 additions & 2 deletions yt/utilities/math_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def periodic_dist(a, b, period, periodicity=(True, True, True)):
c = np.empty((2,) + a.shape, dtype="float64")
c[0,:] = np.abs(a - b)

p_directions = [i for i,p in enumerate(periodicity) if p is True]
np_directions = [i for i,p in enumerate(periodicity) if p is False]
p_directions = [i for i,p in enumerate(periodicity) if p]
np_directions = [i for i,p in enumerate(periodicity) if not p]
for d in p_directions:
c[1,d,:] = period[d,:] - np.abs(a - b)[d,:]
for d in np_directions:
Expand Down
2 changes: 1 addition & 1 deletion yt/utilities/parallel_tools/parallel_analysis_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def enable_parallelism(suppress_logging=False, communicator=None):
ytcfg["yt","__global_parallel_size"] = str(communicator.size)
ytcfg["yt","__parallel"] = "True"
if exe_name == "embed_enzo" or \
("_parallel" in dir(sys) and sys._parallel is True):
("_parallel" in dir(sys) and sys._parallel):
ytcfg["yt","inline"] = "True"
if communicator.rank > 0:
if ytcfg.getboolean("yt","LogFile"):
Expand Down
2 changes: 1 addition & 1 deletion yt/utilities/parameter_file_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, in_memory=False):
Otherwise, use read-only settings.
"""
if self._register is False: return
if not self._register: return
if ytcfg.getboolean("yt", "StoreParameterFiles"):
self._read_only = False
self.init_db()
Expand Down
2 changes: 1 addition & 1 deletion yt/visualization/line_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def _get_plot_instance(self, field):
return plot

def _setup_plots(self):
if self._plot_valid is True:
if self._plot_valid:
return
for plot in self.plots.values():
plot.axes.cla()
Expand Down
2 changes: 1 addition & 1 deletion yt/visualization/particle_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def __init__(self, ds, axis, fields=None, color='b', center='c', width=None,

self.set_axes_unit(axes_unit)

if self._use_cbar is False:
if not self._use_cbar:
self.hide_colorbar()


Expand Down
Loading

0 comments on commit 65219a6

Please sign in to comment.