Skip to content

Commit 4376c38

Browse files
committed
ran ruff pydocstyle ruleset
1 parent e148415 commit 4376c38

File tree

12 files changed

+37
-14
lines changed

12 files changed

+37
-14
lines changed

RATapi/controls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,11 @@ def initialise_IPC(self):
205205
def sendStopEvent(self):
206206
"""Sends the stop event via the inter-process communication file.
207207
208-
Warnings
208+
Warnings:
209209
--------
210210
UserWarning
211211
Raised if we try to delete an IPC file that was not initialised.
212+
212213
"""
213214
if os.path.isfile(self._IPCFilePath):
214215
with open(self._IPCFilePath, "wb") as f:

RATapi/examples/bayes_benchmark/bayes_benchmark.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
This example compares three Bayesian posteriors for a low-dimensional
1+
"""This example compares three Bayesian posteriors for a low-dimensional
32
example: a posterior generated by DREAM, one generated by NS, and
43
one calculated directly.
54
@@ -191,6 +190,7 @@ def calculate_posterior(roughness_index: int, background_index: int) -> float:
191190
-------
192191
float
193192
The value of exp(-chi^2 / 2) for the given roughness and background values.
193+
194194
"""
195195
problem.parameters[0].value = roughness[roughness_index]
196196
problem.background_parameters[0].value = background[background_index]
@@ -265,6 +265,7 @@ def calculate_posterior(roughness_index: int, background_index: int, scalefactor
265265
-------
266266
float
267267
The value of exp(-chi^2 / 2) for the given roughness and background values.
268+
268269
"""
269270
problem.parameters[0].value = roughness[roughness_index]
270271
problem.background_parameters[0].value = background[background_index]
@@ -300,6 +301,7 @@ def plot_posterior_comparison(
300301
The BayesResults object from a DREAM calculation.
301302
calc_results : CalculationResults
302303
The results from a direct calculation.
304+
303305
"""
304306
num_params = calc_results.distribution.ndim
305307
fig, axes = plt.subplots(3, num_params, figsize=(3 * num_params, 9))

RATapi/inputs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class FileHandles:
5656
----------
5757
files : ClassList[CustomFile]
5858
A list of custom file models.
59+
5960
"""
6061

6162
def __init__(self, files=None):

RATapi/models.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ class Contrast(RATModel):
179179
@classmethod
180180
def domain_ratio_error(cls, data: Any):
181181
"""If the extra input 'domain_ratio' is given, give a more descriptive error."""
182-
183182
if isinstance(data, dict) and data.get("domain_ratio", False):
184183
raise ValueError(
185184
"The Contrast class does not support domain ratios. Use the ContrastWithRatio class instead."
@@ -474,7 +473,6 @@ class Layer(RATModel, populate_by_name=True):
474473
@classmethod
475474
def sld_imaginary_error(cls, data: Any):
476475
"""If the extra input 'sld_imaginary' is given, give a more descriptive error."""
477-
478476
if isinstance(data, dict) and data.get("SLD_imaginary", False):
479477
raise ValueError("The Layer class does not support imaginary SLD. Use the AbsorptionLayer class instead.")
480478

RATapi/outputs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def get_field_string(field: str, value: Any, array_limit: int):
2626
-------
2727
field_string : str
2828
The string representation of the field in the RAT output class.
29+
2930
"""
3031
array_text = "Data array: "
3132
if isinstance(value, list) and len(value) > 0:
@@ -182,6 +183,7 @@ class PredictionIntervals(RATResult):
182183
The prediction interval data for SLD of each contrast.
183184
sampleChi : np.ndarray
184185
The value of sumChi at each point of the Markov chain.
186+
185187
"""
186188

187189
reflectivity: list
@@ -191,8 +193,7 @@ class PredictionIntervals(RATResult):
191193

192194
@dataclass
193195
class ConfidenceIntervals(RATResult):
194-
"""
195-
The 65% and 95% confidence intervals for the best fit results.
196+
"""The 65% and 95% confidence intervals for the best fit results.
196197
197198
Attributes
198199
----------
@@ -202,6 +203,7 @@ class ConfidenceIntervals(RATResult):
202203
The 65% confidence intervals for each fit parameter.
203204
mean : np.ndarray
204205
The mean values for each fit parameter.
206+
205207
"""
206208

207209
percentile95: np.ndarray

RATapi/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class ProgressBar:
1616
----------
1717
display : bool, default: True
1818
Indicates if displaying is allowed
19+
1920
"""
2021

2122
def __init__(self, display=True):
@@ -41,6 +42,7 @@ def updateProgress(self, event):
4142
----------
4243
event: ProgressEventData
4344
The progress event data.
45+
4446
"""
4547
if self.pbar is None:
4648
self.pbar = tqdm(**self.tqdm_kwargs)
@@ -64,6 +66,7 @@ class TextOutput:
6466
----------
6567
display : bool, default: True
6668
Indicates if displaying is allowed
69+
6770
"""
6871

6972
def __init__(self, display=True):
@@ -82,6 +85,7 @@ def printMessage(self, msg):
8285
----------
8386
msg: str
8487
The event message.
88+
8589
"""
8690
print(msg, end="")
8791

RATapi/utils/convert.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def r1_to_project_class(filename: Union[str, PathLike]) -> Project:
4646
def zip_if_several(*params) -> Union[tuple, list[tuple]]:
4747
"""Zips parameters if necessary, but can handle single-item parameters.
4848
49-
Examples:
49+
Examples
50+
--------
5051
zip_if_several([1, 2], [3, 4]) = [(1, 3), (2, 4)]
5152
zip_if_several(1, 2, 3) = [(1, 2, 3)]
5253
@@ -79,6 +80,7 @@ def read_param(names, constrs, values, fits):
7980
-------
8081
ClassList
8182
A list of all relevant parameters.
83+
8284
"""
8385

8486
def fix_invalid_constraints(name: str, constrs: tuple[float, float], value: float) -> tuple[float, float]:
@@ -334,6 +336,7 @@ def project_class_to_r1(
334336
-------
335337
dict or None
336338
If `return_struct` is True, return the r1 struct. Else, return nothing.
339+
337340
"""
338341

339342
def convert_parameters(
@@ -355,6 +358,7 @@ def convert_parameters(
355358
-------
356359
dict
357360
A dict of the relevant struct fields.
361+
358362
"""
359363
output = {
360364
name: [p.name for p in params],

RATapi/utils/plotting.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def plot_ref_sld_helper(
7979
Controls whether the grid is shown
8080
show_legend : bool, default: True
8181
Controls whether the lengend is shown
82+
8283
Returns
8384
-------
8485
fig : matplotlib.pyplot.figure
@@ -345,6 +346,7 @@ def plotEvent(self, event):
345346
----------
346347
event: PlotEventData
347348
The plot event data.
349+
348350
"""
349351
if not self.closed and self.figure.number in plt.get_fignums():
350352
plot_ref_sld_helper(event, self.figure)
@@ -675,6 +677,7 @@ def panel_plot_helper(plot_func: Callable, indices: list[int]) -> matplotlib.fig
675677
-------
676678
matplotlib.figure.Figure
677679
A figure containing a grid of plots over the indices in `indices`.
680+
678681
"""
679682
nplots = len(indices)
680683
nrows, ncols = ceil(sqrt(nplots)), round(sqrt(nplots))
@@ -747,7 +750,6 @@ def plot_hists(
747750
If `return_fig` is True, return the figure - otherwise, return nothing.
748751
749752
"""
750-
751753
# first convert names to indices if given
752754
fitname_to_index = partial(name_to_index, names=results.fitNames)
753755

pyproject.toml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ line-length = 120
1111
extend-exclude = ["*.ipynb"]
1212

1313
[tool.ruff.lint]
14-
select = ["E", "F", "UP", "B", "SIM", "I"]
15-
ignore = ["SIM103", "SIM108"]
14+
select = ["E", # pycodestyle errors
15+
"F", # pyflakes
16+
"UP", # pyupgrade
17+
"B", # flake8-bugbear
18+
"SIM", # flake8-simplify
19+
"I", # isort
20+
"D"] # pydocstyle
21+
22+
ignore = ["SIM103", # needless bool
23+
"SIM108", # if-else block instead of ternary operator
24+
"D105", # undocumented __init__
25+
"D107"] # undocumented magic method
1626

1727
[tool.ruff.lint.flake8-pytest-style]
1828
fixture-parentheses = false

tests/conftest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6548,7 +6548,6 @@ def dream_results():
65486548
@pytest.fixture
65496549
def r1_default_project():
65506550
"""The Project corresponding to the data in R1defaultProject.mat."""
6551-
65526551
project = RATapi.Project(
65536552
name="defaultProject",
65546553
calculation="normal",

0 commit comments

Comments
 (0)