Skip to content

Commit

Permalink
Merge pull request #1052 from wright-group/codeql_errors
Browse files Browse the repository at this point in the history
Fix errors identified by CodeQL
  • Loading branch information
kameyer226 committed Mar 22, 2022
2 parents 25c161c + 0adf49a commit 791d578
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
### Fixed
- `data.from_Solis`: import works without metadata
- `unit` conversions of `None` to `None` no longer throws a warning.
- better error messages for some functions
- remove unused imports
- remove unused variables

Expand Down
3 changes: 3 additions & 0 deletions WrightTools/_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def __new__(cls, *args, **kwargs):
shutil.copyfile(src=str(filepath), dst=p)
elif edit_local and filepath:
p = filepath
else:
raise ValueError("filepath must be provided if edit_local is True")
p = str(p)
for i in Group._instances.keys():
if i.startswith(os.path.abspath(p) + "::"):
Expand Down Expand Up @@ -290,6 +292,7 @@ def close(self):
# ---Blaise 2018-01-08
try:
self.file.flush()
fd = None
try:
# Obtaining the file descriptor must be done prior to closing
fd = self.fid.get_vfd_handle()
Expand Down
2 changes: 2 additions & 0 deletions WrightTools/artists/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ def add_sideplot(self, along, pad=0, height=0.75, ymin=0, ymax=1.1):
elif along == "y":
ax = self.sidey = divider.append_axes("right", height, pad=pad, sharey=self)
ax.transposed = True
else:
raise ValueError("unexpacted value for 'along': {along}, expected 'x' or 'y'")
# beautify
if along == "x":
ax.set_ylim(ymin, ymax)
Expand Down
2 changes: 2 additions & 0 deletions WrightTools/artists/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def add_sideplot(
axCorr = divider.append_axes("top", height, pad=pad, sharex=ax)
elif along == "y":
axCorr = divider.append_axes("right", height, pad=pad, sharey=ax)
else:
raise ValueError(f"unexpected 'along': {along}, expected 'x' or 'y'")
axCorr.autoscale(False)
axCorr.set_adjustable("box")
# bin
Expand Down
6 changes: 5 additions & 1 deletion WrightTools/data/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def bring_to_front(self, channel):
new.insert(0, new.pop(channel_index))
self.channel_names = new

def chop(self, *args, at={}, parent=None, verbose=True) -> wt_collection.Collection:
def chop(self, *args, at=None, parent=None, verbose=True) -> wt_collection.Collection:
"""Divide the dataset into its lower-dimensionality components.
Parameters
Expand Down Expand Up @@ -370,6 +370,8 @@ def chop(self, *args, at={}, parent=None, verbose=True) -> wt_collection.Collect
args[i] = wt_kit.string2identifier(arg)

# normalize the at keys to the natural name
if at is None:
at = {}
for k in [ak for ak in at.keys() if type(ak) == str]:
for op in operators:
if op in k:
Expand Down Expand Up @@ -1901,6 +1903,8 @@ def remove_constant(self, constant, *, verbose=True):
constant_index = wt_kit.get_index(self.constant_expressions, constant)
elif isinstance(constant, Constant):
constant_index = wt_kit.get_index(self.constants, constant)
else:
raise TypeError(f"unsupported type for 'constant': {type(constant).__name__}")
constant = self._constants[constant_index]
self._constants.pop(constant_index)
self.flush()
Expand Down
2 changes: 2 additions & 0 deletions WrightTools/diagrams/WMEL.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ def add_arrow(
line = subplot.plot(
xi, yi, linestyle="-", color=color, linewidth=2, solid_capstyle="butt"
)
else:
raise ValueError("unexpected value for 'kind': {kind}, expected ('ket', 'bra', 'out')")
# add arrow head
arrow_head = subplot.arrow(
self.x_pos[number],
Expand Down
2 changes: 1 addition & 1 deletion tests/data/chop.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_3D_to_2D_signed():
chop = data.chop("wm", "w2")
assert len(chop) == 11
for d in chop.values():
assert data.signal_diff.signed
assert d.signal_diff.signed
data.close()
chop.close()

Expand Down

0 comments on commit 791d578

Please sign in to comment.