Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmdstanpy/cmdstan_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,12 @@ def validate(self) -> None:
self._logger.info(
'created output directory: %s', self.output_dir
)
except (RuntimeError, PermissionError):
except (RuntimeError, PermissionError) as exc:
raise ValueError(
'invalid path for output files, no such dir: {}'.format(
self.output_dir
)
)
) from exc
if not os.path.isdir(self.output_dir):
raise ValueError(
'specified output_dir not a directory: {}'.format(
Expand All @@ -608,11 +608,11 @@ def validate(self) -> None:
with open(testpath, 'w+'):
pass
os.remove(testpath) # cleanup
except Exception:
except Exception as exc:
raise ValueError(
'invalid path for output files,'
' cannot write to dir: {}'.format(self.output_dir)
)
) from exc

if self.seed is None:
rng = RandomState()
Expand Down
6 changes: 3 additions & 3 deletions cmdstanpy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,13 @@ def generate_quantities(
runset._csv_files = sample_csv_files
sample_fit = CmdStanMCMC(runset)
sample_drawset = sample_fit.draws_as_dataframe()
except ValueError as e:
except ValueError as exc:
raise ValueError(
'Invalid mcmc_sample, error:\n\t{}\n\t'
' while processing files\n\t{}'.format(
repr(e), '\n\t'.join(sample_csv_files)
repr(exc), '\n\t'.join(sample_csv_files)
)
)
) from exc

generate_quantities_args = GenerateQuantitiesArgs(
csv_files=sample_csv_files
Expand Down
4 changes: 2 additions & 2 deletions cmdstanpy/stanfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ def save_csvfiles(self, dir: str = None) -> None:
with open(test_path, 'w'):
pass
os.remove(test_path) # cleanup
except (IOError, OSError, PermissionError):
raise Exception('cannot save to path: {}'.format(dir))
except (IOError, OSError, PermissionError) as exc:
raise Exception('cannot save to path: {}'.format(dir)) from exc

for i in range(self.chains):
if not os.path.exists(self._csv_files[i]):
Expand Down
8 changes: 4 additions & 4 deletions cmdstanpy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,8 @@ def parse_rdump_value(rhs: str) -> Union[int, float, np.array]:
val = float(rhs)
else:
val = int(rhs)
except TypeError:
raise ValueError('bad value in Rdump file: {}'.format(rhs))
except TypeError as exc:
raise ValueError('bad value in Rdump file: {}'.format(rhs)) from exc
return val


Expand Down Expand Up @@ -691,10 +691,10 @@ def scan_metric(fd: TextIO, config_dict: Dict, lineno: int) -> int:
)
try:
float(stepsize.strip())
except ValueError:
except ValueError as exc:
raise ValueError(
'line {}: invalid stepsize: {}'.format(lineno, stepsize)
)
) from exc
line = fd.readline().strip()
lineno += 1
if not (
Expand Down