Skip to content

Commit 20f423e

Browse files
authored
Merge pull request #80 from dstansby/pydocstyle
Add docstrings throughout
2 parents b656cba + d3785ee commit 20f423e

File tree

7 files changed

+71
-17
lines changed

7 files changed

+71
-17
lines changed

Diff for: pyproject.toml

+18-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,23 @@ profile = "black"
1414
line_length = 79
1515

1616
[tool.ruff]
17-
1817
target-version = "py38"
19-
select = ["I", "UP", "F", "E", "W"]
18+
select = ["I", "UP", "F", "E", "W", "D"]
19+
ignore = [
20+
"D100", # Missing docstring in public module
21+
"D104", # Missing docstring in public package
22+
"D200", # One-line docstring should fit on one line
23+
"D205", # 1 blank line required between summary line and description
24+
"D400", # First line should end with a period
25+
"D401", # First line of docstring should be in imperative mood
26+
27+
]
2028
fix = true
29+
30+
[tool.ruff.per-file-ignores]
31+
"docs/*" = ["D"]
32+
"examples/*" = ["D"]
33+
"src/napari_matplotlib/tests/*" = ["D"]
34+
35+
[tool.ruff.pydocstyle]
36+
convention = "numpy"

Diff for: src/napari_matplotlib/base.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020

2121
class NapariMPLWidget(QWidget):
2222
"""
23-
Base widget that can be embedded as a napari widget and contains a
24-
Matplotlib canvas.
23+
Base Matplotlib canvas. Widget that can be embedded as a napari widget.
2524
2625
This creates a single FigureCanvas, which contains a single Figure.
2726
@@ -81,7 +80,9 @@ def current_z(self) -> int:
8180

8281
def setup_callbacks(self) -> None:
8382
"""
84-
Setup callbacks for:
83+
Sets up callbacks.
84+
85+
Sets up callbacks for:
8586
- Layer selection changing
8687
- z-step changing
8788
"""
@@ -146,7 +147,7 @@ def apply_napari_colorscheme(self):
146147

147148
def _on_update_layers(self) -> None:
148149
"""
149-
This function is called when self.layers is updated via
150+
Function is called when self.layers is updated via
150151
``self.update_layers()``.
151152
152153
This is a no-op, and is intended for derived classes to override.

Diff for: src/napari_matplotlib/histogram.py

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
2626
self.update_layers(None)
2727

2828
def clear(self) -> None:
29+
"""
30+
Clear the axes.
31+
"""
2932
self.axes.clear()
3033

3134
def draw(self) -> None:

Diff for: src/napari_matplotlib/scatter.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414

1515
class ScatterBaseWidget(NapariMPLWidget):
16+
"""
17+
Base class for widgets that scatter two datasets against each other.
18+
"""
19+
1620
# opacity value for the markers
1721
_marker_alpha = 0.5
1822

@@ -91,7 +95,8 @@ class ScatterWidget(ScatterBaseWidget):
9195
input_layer_types = (napari.layers.Image,)
9296

9397
def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
94-
"""Get the plot data.
98+
"""
99+
Get the plot data.
95100
96101
Returns
97102
-------
@@ -110,6 +115,10 @@ def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
110115

111116

112117
class FeaturesScatterWidget(ScatterBaseWidget):
118+
"""
119+
Widget to scatter data stored in two layer feature attributes.
120+
"""
121+
113122
n_layers_input = Interval(1, 1)
114123
# All layers that have a .features attributes
115124
input_layer_types = (
@@ -133,7 +142,9 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
133142

134143
@property
135144
def x_axis_key(self) -> Optional[str]:
136-
"""Key to access x axis data from the FeaturesTable"""
145+
"""
146+
Key to access x axis data from the FeaturesTable.
147+
"""
137148
return self._x_axis_key
138149

139150
@x_axis_key.setter
@@ -143,16 +154,23 @@ def x_axis_key(self, key: Optional[str]) -> None:
143154

144155
@property
145156
def y_axis_key(self) -> Optional[str]:
146-
"""Key to access y axis data from the FeaturesTable"""
157+
"""
158+
Key to access y axis data from the FeaturesTable.
159+
"""
147160
return self._y_axis_key
148161

149162
@y_axis_key.setter
150163
def y_axis_key(self, key: Optional[str]) -> None:
164+
"""
165+
Set the y-axis key.
166+
"""
151167
self._y_axis_key = key
152168
self._draw()
153169

154170
def _set_axis_keys(self, x_axis_key: str, y_axis_key: str) -> None:
155-
"""Set both axis keys and then redraw the plot"""
171+
"""
172+
Set both axis keys and then redraw the plot.
173+
"""
156174
self._x_axis_key = x_axis_key
157175
self._y_axis_key = y_axis_key
158176
self._draw()
@@ -175,7 +193,8 @@ def _get_valid_axis_keys(
175193
return self.layers[0].features.keys()
176194

177195
def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
178-
"""Get the plot data.
196+
"""
197+
Get the plot data.
179198
180199
Returns
181200
-------
@@ -214,8 +233,7 @@ def _get_data(self) -> Tuple[List[np.ndarray], str, str]:
214233

215234
def _on_update_layers(self) -> None:
216235
"""
217-
This is called when the layer selection changes by
218-
``self.update_layers()``.
236+
Called when the layer selection changes by ``self.update_layers()``.
219237
"""
220238
if hasattr(self, "_key_selection_widget"):
221239
self._key_selection_widget.reset_choices()

Diff for: src/napari_matplotlib/slice.py

+9
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def __init__(self, napari_viewer: napari.viewer.Viewer):
5050

5151
@property
5252
def layer(self):
53+
"""
54+
Layer being plotted.
55+
"""
5356
return self.layers[0]
5457

5558
@property
@@ -70,6 +73,9 @@ def current_dim_index(self) -> int:
7073

7174
@property
7275
def selector_values(self) -> Dict[str, int]:
76+
"""
77+
Values of the slice selectors.
78+
"""
7379
return {d: self.slice_selectors[d].value() for d in _dims_sel}
7480

7581
def update_slice_selectors(self) -> None:
@@ -107,6 +113,9 @@ def get_xy(self) -> Tuple[np.ndarray, np.ndarray]:
107113
return x, y
108114

109115
def clear(self) -> None:
116+
"""
117+
Clear the axes.
118+
"""
110119
self.axes.cla()
111120

112121
def draw(self) -> None:

Diff for: src/napari_matplotlib/tests/test_scatter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def make_labels_layer_with_features():
3434

3535

3636
def test_features_scatter_get_data(make_napari_viewer):
37-
"""test the get data method"""
37+
"""Test the get data method"""
3838
# make the label image
3939
label_image, feature_table = make_labels_layer_with_features()
4040

@@ -59,7 +59,7 @@ def test_features_scatter_get_data(make_napari_viewer):
5959

6060

6161
def test_get_valid_axis_keys(make_napari_viewer):
62-
"""test the values returned from
62+
"""Test the values returned from
6363
FeaturesScatterWidget._get_valid_keys() when there
6464
are valid keys.
6565
"""
@@ -76,7 +76,7 @@ def test_get_valid_axis_keys(make_napari_viewer):
7676

7777

7878
def test_get_valid_axis_keys_no_valid_keys(make_napari_viewer):
79-
"""test the values returned from
79+
"""Test the values returned from
8080
FeaturesScatterWidget._get_valid_keys() when there
8181
are not valid keys.
8282
"""

Diff for: src/napari_matplotlib/util.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33

44
class Interval:
5+
"""
6+
An integer interval.
7+
"""
8+
59
def __init__(self, lower_bound: Optional[int], upper_bound: Optional[int]):
610
"""
711
Parameters
@@ -19,7 +23,10 @@ def __init__(self, lower_bound: Optional[int], upper_bound: Optional[int]):
1923
self.lower = lower_bound
2024
self.upper = upper_bound
2125

22-
def __contains__(self, val):
26+
def __contains__(self, val: int) -> bool:
27+
"""
28+
Return True if val is in the current interval.
29+
"""
2330
if not isinstance(val, int):
2431
raise ValueError("variable must be an integer")
2532
if self.lower is not None and val < self.lower:

0 commit comments

Comments
 (0)