Skip to content

Commit

Permalink
fix type comparisons to use isinstance instead
Browse files Browse the repository at this point in the history
  • Loading branch information
bhazelton committed Aug 8, 2023
1 parent 24a1412 commit 14aae45
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pyuvdata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5061,13 +5061,13 @@ def parse_ants(uv, ant_str, print_toggle=False, x_orientation=None):

for ant_i in ant_i_list:
include_i = True
if type(ant_i) == str and ant_i.startswith("-"):
if isinstance(ant_i, str) and ant_i.startswith("-"):
ant_i = ant_i[1:] # nibble the - off the string
include_i = False

for ant_j in ant_j_list:
include_j = True
if type(ant_j) == str and ant_j.startswith("-"):
if isinstance(ant_j, str) and ant_j.startswith("-"):
ant_j = ant_j[1:]
include_j = False

Expand Down
8 changes: 4 additions & 4 deletions pyuvdata/uvdata/aipy_extracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def parse_ants(ant_str, nants):
ajs = m[6].split(",")

for i in ais:
if type(i) == str and i.startswith("-"):
if isinstance(i, str) and i.startswith("-"):
i = i[1:] # nibble the - off the string
include_i = 0
else:
Expand All @@ -164,7 +164,7 @@ def parse_ants(ant_str, nants):
for j in ajs:
include = None

if type(j) == str and j.startswith("-"):
if isinstance(j, str) and j.startswith("-"):
j = j[1:]
include_j = 0
else:
Expand Down Expand Up @@ -217,7 +217,7 @@ def uv_selector(uv, ants=-1, pol_str=-1):
None
"""
if ants != -1:
if type(ants) == str:
if isinstance(ants, str):
ants = parse_ants(ants, uv["nants"])

for cnt, (bl, include, pol) in enumerate(ants):
Expand Down Expand Up @@ -421,7 +421,7 @@ def _rdhd(self, name):

if len(rv) == 1:
return rv[0]
elif type(rv) == str:
elif isinstance(rv, str):
return rv
else:
return np.array(rv)
Expand Down
8 changes: 4 additions & 4 deletions pyuvdata/uvdata/mir_meta_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def __add__(
If attempting to combine this object with another of a different type.
"""
# First up, make sure we have two objects of the same dtype
if type(self) != type(other):
if not isinstance(other, self.__class__):
raise ValueError("Both objects must be of the same type.")

if other._data is None:
Expand Down Expand Up @@ -1584,7 +1584,7 @@ def _generate_new_header_keys(self, other):
If the two objects are not of the same type.
"""
# First up, make sure we have two objects of the same dtype
if type(self) != type(other):
if not isinstance(other, self.__class__):
raise ValueError("Both objects must be of the same type.")

# If no data are loaded, or if there is no header key, then this is basically
Expand Down Expand Up @@ -1917,7 +1917,7 @@ def _add_check(self, other, merge=None, overwrite=None, discard_flagged=False):
but the header keys (and their respective index positions) are different.
"""
# First up, make sure we have two objects of the same dtype
if type(self) != type(other):
if not isinstance(other, self.__class__):
raise ValueError("Both objects must be of the same type.")

if merge and discard_flagged:
Expand Down Expand Up @@ -2927,7 +2927,7 @@ def _generate_new_header_keys(self, other):
If the two objects are not of the same type.
"""
# First up, make sure we have two objects of the same dtype
if type(self) != type(other):
if not isinstance(other, self.__class__):
raise ValueError("Both objects must be of the same type.")

index_dict = {}
Expand Down
6 changes: 3 additions & 3 deletions pyuvdata/uvdata/miriad.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def _read_miriad_metadata(self, uv, correct_lat_lon=True):

# keep all single valued extra_variables as extra_keywords
for key in check_variables.keys():
if type(check_variables[key]) == str:
if isinstance(check_variables[key], str):
value = check_variables[key].replace("\x00", "")
# check for booleans encoded as strings
if value == "True":
Expand All @@ -690,7 +690,7 @@ def _read_miriad_metadata(self, uv, correct_lat_lon=True):
key not in ["vartable", "history", "obstype"]
and key not in other_miriad_variables
):
if type(uv[key]) == str:
if isinstance(uv[key], str):
value = uv[key].replace("\x00", "")
value = uv[key].replace("\x01", "")
if value == "True":
Expand Down Expand Up @@ -1988,7 +1988,7 @@ def write_miriad(
value = float(value)
elif issubclass(value.dtype.type, np.complexfloating):
raise_type_error = True
elif type(value) == bool:
elif isinstance(value, bool):
value = str(value)
elif type(value) not in types.keys():
raise_type_error = True
Expand Down

0 comments on commit 14aae45

Please sign in to comment.